ループ構文(PHP版)
while構文
<?php
$i = 0;
$tmp = array("_abc", "_def", "_ghi" );
while($i < 3) {
print($tmp[$i]);
$i++;
}
?>
for構文
<?php
$i = 0;
$tmp = array("_abc", "_def", "_ghi" );
for($i = 0; $i < 3; $i++) {
print($tmp[$i]);
}
?>
do~while構文
<?php
$i = 0;
$tmp = array("_abc", "_def", "_ghi" );
do {
print($tmp[$i]);
$i++;
} while($i < 3);
?>
foreach構文
配列の各要素について処理を実行する。
このとき配列ArrのキーKeyと値Valueを設定する
[基本形]
foreach( 配列 as $key => $value) {
処理スクリプト
}
<?php
$arr = array("A" => "apple", "B" => "Black", "C" => "Car");
foreach( $arr as $key => $value) {
print("key[$key] value[$value]<br>");
}
?>
最終更新:2012年09月24日 11:42