Recursive PHP?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jørn Dahl-Stamnes

    #1

    Recursive PHP?

    Do PHP support recursive calling, like this:

    function some_func ($some_arg)
    {
    $count = 0;
    // some code
    while (<some condition>)
    {
    if (<some condition>)
    {
    $count += some_func ($some_arg);
    } else {
    ++$count;
    }
    }
    return $count;
    }

    --
    Jørn Dahl-Stamnes

  • Oli Filth

    #2
    Re: Recursive PHP?

    Jørn Dahl-Stamnes said the following on 18/12/2005 09:42:[color=blue]
    > Do PHP support recursive calling, like this:
    >
    > function some_func ($some_arg)
    > {
    > $count = 0;
    > // some code
    > while (<some condition>)
    > {
    > if (<some condition>)
    > {
    > $count += some_func ($some_arg);
    > } else {
    > ++$count;
    > }
    > }
    > return $count;
    > }
    >[/color]

    Did you not think to just try it out?

    --
    Oli

    Comment

    • Andy Hassall

      #3
      Re: Recursive PHP?

      On Sun, 18 Dec 2005 10:42:16 +0100, Jørn Dahl-Stamnes
      <newsmanDELETE@ REMOVEdahl-stamnes.net> wrote:
      [color=blue]
      >Do PHP support recursive calling[/color]



      --
      Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
      http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

      Comment

      • Jørn Dahl-Stamnes

        #4
        Re: Recursive PHP?

        Oli Filth wrote:
        [color=blue]
        > Jørn Dahl-Stamnes said the following on 18/12/2005 09:42:[color=green]
        >> Do PHP support recursive calling, like this:
        >>
        >> function some_func ($some_arg)
        >> {
        >> $count = 0;
        >> // some code
        >> while (<some condition>)
        >> {
        >> if (<some condition>)
        >> {
        >> $count += some_func ($some_arg);
        >> } else {
        >> ++$count;
        >> }
        >> }
        >> return $count;
        >> }
        >>[/color]
        >
        > Did you not think to just try it out?[/color]

        Yes, I did and it did not seem to work. I asked becasue maybe there was some
        hack etc that I needed to do before it worked...

        --
        Jørn Dahl-Stamnes

        Comment

        • Jørn Dahl-Stamnes

          #5
          Re: Recursive PHP?

          Andy Hassall wrote:
          [color=blue]
          > On Sun, 18 Dec 2005 10:42:16 +0100, Jørn Dahl-Stamnes
          > <newsmanDELETE@ REMOVEdahl-stamnes.net> wrote:
          >[color=green]
          >>Do PHP support recursive calling[/color]
          >
          > http://www.php.net/manual/en/language.functions.php[/color]

          A newer version of my local version of the document. It say that it should
          be possible, but this seems not to work on my server (PHP 4.3.9). Do I need
          a newer version of PHP?

          --
          Jørn Dahl-Stamnes

          Comment

          • Oli Filth

            #6
            Re: Recursive PHP?

            Jørn Dahl-Stamnes said the following on 18/12/2005 18:29:[color=blue]
            > Oli Filth wrote:
            >
            >[color=green]
            >>Jørn Dahl-Stamnes said the following on 18/12/2005 09:42:
            >>[color=darkred]
            >>>Do PHP support recursive calling, like this:
            >>>
            >>>function some_func ($some_arg)
            >>>{
            >>> $count = 0;
            >>> // some code
            >>> while (<some condition>)
            >>> {
            >>> if (<some condition>)
            >>> {
            >>> $count += some_func ($some_arg);
            >>> } else {
            >>> ++$count;
            >>> }
            >>> }
            >>> return $count;
            >>>}
            >>>[/color]
            >>
            >>Did you not think to just try it out?[/color]
            >
            >
            > Yes, I did and it did not seem to work. I asked becasue maybe there was some
            > hack etc that I needed to do before it worked...
            >[/color]

            Ah well, you didn't say that! If you're not specific, you usually get a
            condescending answer on Usenet.

            What doesn't work? Did you get any error messages, etc.?

            --
            Oli

            Comment

            • Andy Hassall

              #7
              Re: Recursive PHP?

              On Sun, 18 Dec 2005 19:31:57 +0100, Jørn Dahl-Stamnes
              <newsmanDELETE@ REMOVEdahl-stamnes.net> wrote:
              [color=blue]
              >Andy Hassall wrote:
              >[color=green]
              >> On Sun, 18 Dec 2005 10:42:16 +0100, Jørn Dahl-Stamnes
              >> <newsmanDELETE@ REMOVEdahl-stamnes.net> wrote:
              >>[color=darkred]
              >>>Do PHP support recursive calling[/color]
              >>
              >> http://www.php.net/manual/en/language.functions.php[/color]
              >
              >A newer version of my local version of the document. It say that it should
              >be possible, but this seems not to work on my server (PHP 4.3.9). Do I need
              >a newer version of PHP?[/color]

              No, recursive functions have always worked.

              For a more helpful reply, post more information.

              --
              Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
              http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

              Comment

              • Jørn Dahl-Stamnes

                #8
                Re: Recursive PHP?

                Andy Hassall wrote:
                [color=blue]
                > On Sun, 18 Dec 2005 19:31:57 +0100, Jørn Dahl-Stamnes
                > <newsmanDELETE@ REMOVEdahl-stamnes.net> wrote:
                >[color=green]
                >>Andy Hassall wrote:
                >>[color=darkred]
                >>> On Sun, 18 Dec 2005 10:42:16 +0100, Jørn Dahl-Stamnes
                >>> <newsmanDELETE@ REMOVEdahl-stamnes.net> wrote:
                >>>
                >>>>Do PHP support recursive calling
                >>>
                >>> http://www.php.net/manual/en/language.functions.php[/color]
                >>
                >>A newer version of my local version of the document. It say that it should
                >>be possible, but this seems not to work on my server (PHP 4.3.9). Do I
                >>need a newer version of PHP?[/color]
                >
                > No, recursive functions have always worked.[/color]

                After I saw the example in the document above, I tested it and found out
                that it did work.
                So after looking into my code again, I found a small error that resulted in
                an incorrect return argument, which in the first place looked like it did
                not work.

                Thanks.
                --
                Jørn Dahl-Stamnes

                Comment

                Working...