Recursive Functions are functions that auto-call themself. Generally, a recursive function returns a value that are passed as argument, so the value is passed from an auto-call to the other, until it is returned.
Recursive functions are very useful in equations with factorial numbers and some operatios with multi-dimensional array.
Factorials are written like 6! and this means: 6 * 5 * 4 * 3 * 2 * 1. So 6! is 4320 and 4! is 24.
In the fallowing example we have a recursive function that finds the factorial of a number "$nr" (here 8).

<?php
// this function auto-calls itself (decrementing $nr) until $nr is 0
function factorial($nr) {
  if($nr > 0) $re = $nr * factorial($nr-1);
  else if($nr == 0) $re = 1;

  return $re;
}

echo '8 factorial is: '. factorial(8);        // 8 factorial is: 45360
?>

- To see another example, visit this page: Get all the unique numbers from two-dimensional array.

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag create a highlighted bolded text?
<q> <strong> <em>
<p>Address: <strong>http://CoursesWeb.net/</strong> - Tutorials.</p>
Which of these CSS codes displays the text bolded?
text-size: 18px; font-style: italic; font-weight: 800;
#id {
  font-weight: 800;
}
What JavaScript function can be used to call another function multiple times, to a specified time interval?
setInterval() setTimeout() push()
function someFunction() { alert("CoursesWeb.net"); }
setInterval("someFunction()", 2000);
Click on the correctly defined variable in PHP.
var vname = 8; $vname = 8; $vname == 8;
$vname = 8;
echo $vname;
Recursive Functions in PHP

Last accessed pages

  1. CSS Rhombus Shape (3249)
  2. Horizontal-Vertical Menu with Arrow Keys Navigation (962)
  3. Zuma Kangaroo (2765)
  4. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (54519)
  5. Creating and using classes in JavaScript (868)

Popular pages this month

  1. Bubbles3 (3679)
  2. Butterfly Kyodai (3286)
  3. Zuma Deluxe (2405)
  4. Qwop (1692)
  5. Backgammon (1412)