|
foreach |
|
$youbi = array("Sun", "Mon", "Tue");
$sales = array("tanaka"=>150, "nakamura"=>200); (連想配列)
|
|
|
上記それぞれ、「foreach」を使って配列の要素をすべて取り出す。
|
|
foreach ($youbi as $y) {
echo $y;
}
|
|
| (連想配列の場合) |
|
foreach ($sales as $key => $value) {
echo $key, $value //変数名[$key], [$value]は変更してもOK
}
|
|
|
(実行結果) |
|
SunMonTue |
|
tanaka150nakamura200 |
|