In programming there are sometimes situations when you have to recursively call a function from itself. Novice programmers might find it difficult to understand so here are my two examples written in PHP.
Recursion is a method where the solution to a problem depends on solutions to smaller instances of the same problem. A typical example is factorial which of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. Then 3! equals to 3×2×1=6; 5! = 5×4×3×2×1 = 120, etc.
To program a factorial function we need to note that calculating n factorial will involve multiplying n by n-1 factorial and so on. By using recursive function we do not need to perform cycles: the same function calls itself with diffrent arguments. In PHP it would look like this: