SOLVED: Why won't my function RETURN?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jforloveoftheshirt
Forum Newbie
Posts: 2
Joined: Fri Apr 17, 2009 1:41 am

SOLVED: Why won't my function RETURN?

Post by jforloveoftheshirt »

hi, great forum, a question though!

is there any reason why this piece of code does not generate a return? it does everything awesomely, but will not return!!!!!

FYI the databaseHandler::getRow static function is successfully return the row from mysql.

Code: Select all

 
    function getLinkParts($id, $link_parts)
    {
            if($id['id'] == 0)
            {
                return array_reverse($link_parts);
            } else {
                $r = databaseHandler::getRow("SELECT id, p_id, name FROM categories WHERE id=:id", $id);
                array_push($link_parts, $r['name']);
                $i['id'] = $r['p_id'];
                getLinkParts($i, $link_parts);
            }      
    }
 
i'm using this to call it:

Code: Select all

 
    $id['id'] = 32;
    $r = getLinkParts($id, $ar = array());
    print_r($r);
 
my mind is boggled!
Last edited by jforloveoftheshirt on Fri Apr 17, 2009 8:02 am, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Why won't my function RETURN?

Post by requinix »

Code: Select all

getLinkParts($i, $link_parts);
I don't see a return in there. Which is where you need it.
jforloveoftheshirt
Forum Newbie
Posts: 2
Joined: Fri Apr 17, 2009 1:41 am

Re: Why won't my function RETURN?

Post by jforloveoftheshirt »

I have a return on line 4 below (or line 6 in the snippet above), but I'm guessing this is not allowed? Like so:

Code: Select all

 
             if($id['id'] == 0)
             {
                 return array_reverse($link_parts);
             } else { ...
 
In any case I'll try your suggestion, so

Code: Select all

 
return getLinkParts($i, $link_parts);
 
???

i'll give this is whiz!

UPDATE::

thanks so much tasairis!!! solved my (newbie) problem
Post Reply