Foreach ループ
for (initialization; condition; increment) { code to be executed; }
<?php for($i=1; $i<=100000; $i++) { echo "The number is " . $i . "<br>"; } ?>
while (condition) { code to be executed; }
<?php // If you had an array with fruit names and prices in you could use foreach $fruit = array( "orange" =--> "5.00", "apple" => "2.50", "banana" => "3.99" ); foreach ($fruit as $key => $value) { "$key is $value dollars"; } ?>
<?php // While Loop $a=0; while($a < 1000) { $a++; } ?>
<?php // For Loop for($a = 0; $a < 1000;) { $a++; } ?>
<?php $test = array(1 => "cat", "dog" => 0, "red" => "green", 5 => 4, 3, "me"); $keys = array_keys($test); $size = sizeOf($keys); for($a = 0; $a < $size; $a++) { $t = $test[$keys[$a]]; } ?>
<?php $test = array(1 => "cat", "dog" => 0, "red" => "green", 5 => 4, 3, "me"); foreach($test as $t) { } ?>
以上がPHPのFor、while、foreachの比較説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。