循环添加数组元素
loop addition array elements
$array = array(1,2,3);
do
{
and start to add last digit to previous and put the new one as last element in array
$value = $array[count($array)-1] + $array[count($array)-2];
var_dump($value);
array_push($array, $value);
}
while (count($array) = 10);
print_r($array);
我整天都在尝试了解如何推送新值,直到数组中的元素变成十个
最终程序应该做这样的事情:
1+1=2; 1+2=3; 2+3=5; 3+5=8;……
1,1,2,3,5,8....
你while
条件错误:while (count($array) = 10);
应该是while (count($array) <= 10);
$array = array(1,2,3);
do
{
and start to add last digit to previous and put the new one as last element in array
$value = $array[count($array)-1] + $array[count($array)-2];
var_dump($value);
array_push($array, $value);
}
while (count($array) = 10);
print_r($array);
我整天都在尝试了解如何推送新值,直到数组中的元素变成十个
最终程序应该做这样的事情:
1+1=2; 1+2=3; 2+3=5; 3+5=8;…… 1,1,2,3,5,8....
你while
条件错误:while (count($array) = 10);
应该是while (count($array) <= 10);