A function with the following signature: function exponentArr($num) { }
Such that when $num = 10, the function returns an array of
[1,2,4,8,16,32,64,128,256,512,1024]
A function with the following signature: function exponentArr($num) { }
Such that when $num = 10, the function returns an array of
[1,2,4,8,16,32,64,128,256,512,1024]
You can do this:
function exponentArr($num){
$arr = array();
for($i=0;$i <= $num;$i++){
$arr[$i] = pow(2, $i);
}
return $arr;
}
This will give you an array $arr
with the required output.
Try this, Working as you mentioned.
function powArr($number){
for($i=0;$i < $number;$i++){
$array[$i] = pow(2, $i);
}
return $array;
}
This is Fibonacci sequence
Try this:
$fib = [1,0];
for($i=0; $i<$num; $i++) {
$next = array_sum($fib);
array_shift($fib);
array_push($fib,$next);
echo $next.", ";
}