PHP For ??
PHP ?? - For ??
??? ???? ?? ??? ??? true? ?? ?? ??? ?????.
for ??
for ??? ?????? ??? ??? ?? ? ? ?????. ???.
for ??? ??? while ??? ???? ??? ????? ? ? ????
for (expr1; expr2; expr3)
?
for ???? ? ?? ???? ????
? ? ?? ??? expr1? ?? ?? ???? ? ?? ?????
? ? ?? ??? expr2? ?? ??? ? ?? ?? ???? ????? , ?? ??? true?? ??? ????, false? ???? ??? ?????.
????? ? ?? ??? expr3? ?? ??? ? ?? ??? ?????.
??
for(???; ??; ??)
{
??? ??;
}
????:
· ???: ?? ???? ???? ? ???? ?? ?? ??????(?, ?? ?? ? ? ? ???? ?? ??? ? ??).
· ??: ?? ?? ??. TRUE?? ??? ?????. FALSE?? ??? ?????.
· ??: ?? ???? ????? ? ?????(??? ?? ??? ???? ?? ??? ? ??).
??: ?? ?? ? ? ?? ????? ?? ??? ?? ???(??? ??)? ?? ? ????.
?
?? ???? ?? ? i=1? ???? ??? ?????. ?? i? 5?? ??? ?? ? ??? ?? ?????. ??? ??? ??? ?? i? 1? ?????.
<html> <body> <?php for ($i=1; $i<=5; $i++) { echo "The number is " . $i . "<br>"; } ?> </body> </html>
while ??? ?? ??
$num = 1;
while ($num < = 5) {
echo $num;
$num++;
}
for ??? ???? ??
? ??? ? ????. for ($num = 1; $num <= 5; $num++) {
echo $num;
}
??? ????? for ??? while ??? ??? ??? ?????
foreach ??
foreach ??? ??.
??? PHP?? ??? ???? ? ??? ???? ?? ?? ?? ????.
foreach(array_variable as val)
?
array_variable ?? ??? ?????. ? ?? ?? ?? ? ??? ?? ?? val? ??? ?????. ????? ?? ?? ?? ????
foreach($arr as $item) {
echo "<" . $item . ">";
}
foreach($array as $value)
{ ??? ?????;
}
??? ??? ??? ?? ?? ??? ?? $value ??(?? ???? ??? ?????.) ?? ????? ??? ?? ?? ? ? ????.
?
?? ?? ??? ??? ?? ???? ??? ?????.
<html> <body> <?php $x=array("one","two","three"); foreach ($x as $value) { echo $value . "<br>"; } ?> </body> </html>
Foreach?? ? ?? ???? ????. ??? ??? ????
foreach (array_variable as key => val)
?
key? ??? ??? ????, val? ??? ?? ?????. ??, ?? ?? ??? ?? ??? ?? ? ??? ? ?? 0?? ???? ???? ?????.
?? ? ??
??? ?? ???? ?? ??? ????? ?? ?? ??? ??? ? ????
? break ? ???? ????? ??? ? ?? ???? ????
? Continue? ?? ???? ????? ??? ?? ???? ?? ??? ?????
??? ?? ??? ??? ?? ????. ?? ???? ??? ? ??? ?? ?????. ?? ???? ????? ??? ?????.
?? ???? ?? ?? ??? ??? ????. ??? ??? ?? ?? ???? ?? ??? ?????.