Page 1 of 1

SOLVED: Why won't my function RETURN?

Posted: Fri Apr 17, 2009 1:47 am
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!

Re: Why won't my function RETURN?

Posted: Fri Apr 17, 2009 2:13 am
by requinix

Code: Select all

getLinkParts($i, $link_parts);
I don't see a return in there. Which is where you need it.

Re: Why won't my function RETURN?

Posted: Fri Apr 17, 2009 6:47 am
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