3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

多次元配列のデータの格納及び取り出し方法

Last updated at Posted at 2016-04-08

##配列の作成

$error = [];

##配列へのデータ格納

$error["user"][] = "あああああ";
$error["user"][] = "いいいいい";

$error["pass"][] = "かかかかか";
$error["pass"][] = "ききききき";

##var_dumpして確認

echo "<pre>";
var_dump($error);
echo "</pre>";

##var_dumpの結果

array(2) {
  ["user"]=>
  array(2) {
    [0]=>
    string(15) "あああああ"
    [1]=>
    string(15) "いいいいい"
  }
  ["pass"]=>
  array(2) {
    [0]=>
    string(15) "かかかかか"
    [1]=>
    string(15) "ききききき"
  }
}

##foreachで取り出す

foreach ($error["user"] as $values) {
    echo "<p>{$values}</p>";
}

foreach ($error["pass"] as $values) {
    echo "<p>{$values}</p>";
}

##実行結果

あああああ

いいいいい

かかかかか

ききききき
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?