<?php
/*练习*/
/*for*/
$min = 1;
$max = 10;
$data = range($min, $max);
$count = count($data);
$res = 0;
for ($i = 0; $i < $count; $i++) {
$res += $data[$i];
}
echo $res, '<hr>';
/*while()*/
$min = 1;
$max = 10;
$data = range($min, $max);
$count = count($data);
$res = 0;
while ($i < $count) {
$res += $data[$i];
$i++;
}
echo $res, '<hr>';
/*do~while()*/
$i = 9;
do {
$res += $data[$i];
$i++;
} while ($i < $count);
echo $res, '<hr>';
/*foreach 数组*/
$min = 1;
$max = 15;
$data = range($min, $max);
foreach ($data as $key => $value) {
echo $key . '=>' . $value . '<br>';
}
foreach ($data as $value) {
echo $value . '<br>';
}