创建数组,分别用for/while/foreach()遍历

Original 2019-05-20 16:20:30 151
abstract:$min = 0; $max = 10; $data = range($min,$max); $res = 0; $count = count($data);1、使用forfor($i=0; $i<$count; $i++){     
$min = 0;
$max = 10;
$data = range($min,$max);
$res = 0;
$count = count($data);

1、使用for

for($i=0; $i<$count; $i++){
    $res += $i;
}
echo $res;

2、使用while

$i = 0;
while($i < $count){
    $res += $i;
    $i++;
}
echo $res;

3、使用foreach

foreach($data as $value){
    $res += $value;
}
echo $res;


Correcting teacher:查无此人Correction time:2019-05-21 09:09:34
Teacher's summary:完成的不错。for和while是计算循环,foreach是数组循环。继续加油。

Release Notes

Popular Entries