「PHP」foreach文で連想配列のキーと値を取得するサンプル

PHPコード

<?php
$dep = [
            '101' => 'design',
            '102' => 'programe',
            '103' => 'pm',
                '104' => 'ios'
      ];

foreach ($dep as $key => $value){
      echo "key: ".$key."<br>\n"; 
      echo "value: ".$value."<br>\n"; 
}
?>

結果
key: 101
value: design
key: 102
value: programe
key: 103
value: pm
key: 104
value: ios

PHP

Posted by arkgame