Roberto & Jason thank you for your comments.

Please note the question at the end of this email.

I searched on "recursive PHP functions" and found: 
[thelist] recursive PHP functions
Rob Wilson thelist at
Mon Sep 16 11:00:01 2002

    * Previous message: [thelist] recursive PHP functions
    * Next message: [thelist] pop up window for image without MSIE image
    * Return to the message index sorted by: [ date ] [ thread ] [
subject ] [ author ]

That should read

function recursive ($n)
        if ($n > 10)
                return $n;
        echo "N =" . $n . "<BR>";
        return recursive ($n);
echo "The result:".recursive(1)."<br>";

With the important line being the :

return recursive ( $n );

This allows you to unwind the recursion correctly.


Under   chapter 8 "Variable scope" a mention of
 Static variables also provide one way to deal with recursive functions.
A recursive function is one which calls itself. Care must be taken when
writing a recursive function because it is possible to make it recurse
indefinitely. You must make sure you have an adequate way of terminating
the recursion. The following simple function recursively counts to 10,
using the static variable $count to know when to stop:

function Test()
    static $count = 0;

    echo $count;
    if ($count < 10) {
        Test ();
Interesting but I am still lost as I need some help with
methods/functions within objects:
In the above example do I need to access Test() by:

    if ($count < 10) {
        this->Test ();

Comments please.
Kevin Gordon

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to