How many times will the function counter() be executed in the following code? function counter($start, &$stop) { if ($stop > $start) { return; } counter($start--, ++$stop); } $start = 5; $stop = 2; counter($start, $stop);
Correct answer is 5? brcause:
1 run for start=5 and stop=2
2 run for start=5 and stop=3
3 run for start=5 and stop=4
4 run for start=5 and stop=5
and again... 5 run for start=5 and stop=6 will return without changes for $stop variable
I think the correct answer is B: 4 times.
when running this code in PHP 7.x, i got 4 time notice : Notice: Only variables should be passed by reference in ... on line 9
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
linkmaster
3 years, 1 month agochayan_1089
4 years, 2 months ago[Removed]
4 years, 5 months ago