LoginSignup
0
0

More than 3 years have passed since last update.

多次元配列について

Posted at

配列の中のキーを配列として格納することが可能。

meet.php
$meet = array(
    '鶏肉'=> array(
        'price' => 68,
        'stock' => 10),

    '豚肉' => array(
        'price' => 89,
        'stock' => 15),

    '牛肉' => array(
        'price' => 128,
        'stock' => 8)
        );
foreach($meet as $name => $value) {
    echo $name . 'は、100グラム' . $value['price'] . '円、在庫は' . $value['stock'] . '個です。' . '<br>'; 
}

↓実行結果

meet.php
鶏肉は、100グラム68円在庫は10個です
豚肉は、100グラム89円在庫は15個です
牛肉は、100グラム128円在庫は8個です

複雑な構造を持つデータの配列として定義することが出来ます。

0
0
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
0
0