<?php
function add($min,$max){
$arr=range($min,$max);
$total=0;
for ($i=$min;$i<$max+1;$i++){
$total+=$i;
}
return $total;
}
echo add(1,100);
function add1($min,$max){
$arr=range($min,$max);
$count=count($arr);
$total=0;
$i=0;
while ($i<$count){
$total+=$arr[$i];
$i++;
}
return $total;
}
echo add1(1,100);
function add2($min,$max){
$arr=range($min,$max);
$count=count($arr);
$total=0;
$i=0;
do{
$total+=$arr[$i];
$i++;
}while ($i<$count);
return $total;
}
echo add2(1,100);
function add3($min,$max){
$arr=range($min,$max);
$count=count($arr);
$total=0;
foreach ($arr as $value) {
$total+=$value;
}
return $total;
}
echo add3(1,100);
for,while.do while,foreach循环