foreach 使用例 1
$array = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
foreach ($array as $arr) {
dump($arr);
}
dump($array);
結果 : dump($arr);
{ "1" "2" . . .省略. . . "10" }
dump($array);
array (10) { [0]=> "1" [1]=> "2" . . .省略. . . [9]=> "10" }
foreach 使用例 2
$array = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
foreach ($array as $key => $value) {
echo "key: " . $key . "\n";
echo "value: " . $array[$key] . "\n";
}
結果 :
key: 0 value: "1" key: 1 value: "2" . . .省略. . . key: 9 value: "10"
foreach 使用例 3
$array = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
$index = 0;
foreach ($arr as $key => $val) {
echo "index Value:".$index."\n";
$index++;
}
結果 :
index Value: 0 index Value: 1 index Value: 2 . . .省略 . . index Value: 9