B
B
bilyaev822021-12-07 19:03:00
recursion
bilyaev82, 2021-12-07 19:03:00

Why doesn't recursion work in PHP?

Hello.
There is this code:

$i = 0;
 function func($arr) {
   $keys = array_keys($arr);
  echo $arr[$keys[$i]];
  $i++;
  if($i <= count($keys)){
    func($arr);
  }
}
func(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5]);


Why is there an infinite loop on one?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question