I have simplified this. I have this line of code in a method in a (codeigniter framework) controller:
$the_result = $this->loop1($ordered_bookings);
And this is is the 'loop1' function:
public function loop1($ob, $count=1):array {
++$count;
if($count < 5)
{
$this->loop1($ob, $count);
}
else
{
return array(1, 2, 3);
}
}
What I need to be able to do is loop through loop1 function until certain conditions are met before then returning the results array. Problem is calling the function again at the end of loop1 seems to be returning to the original call, and returning nothing at that (obviously I guess).
If I change the loop1 function to simply this:
public function loop1($ob):array {
return array(1, 2, 3);
}
It works perfectly.
I haven't done this sort of PHP work for a long time and the need to declare a returnType itself was new to me. How can I achieve what I'm aiming for here?
looporloop1inside count condition?return $this->loop1(... you are missing thereturn