I find it difficult to understand the working of this recursive function in PHP. I am not able to follow the code written at return statement. How the total of numbers from 1 to 10 is added? I eagerly want to understand this line return $count + sum($count + 1);
My whole code is:
<?php
function sum($count)
{
if($count <= 10)
{
echo $count;
echo "<br />";
return $count + sum($count + 1);
}
}
$result = sum(1);
echo "The total is $result";
?>
Output:
1
2
3
4
5
6
7
8
9
10
The total is 55
How the total 55 is received in my code? I want to learn it step by step.