how to return static variable PHP

Posted by GOsha on Stack Overflow See other posts from Stack Overflow or by GOsha
Published on 2010-06-14T22:49:48Z Indexed on 2010/06/14 22:52 UTC
Read the original article Hit count: 160

Filed under:
function build_path($cid)
{
    static $fr=array();
    $DB = new MySQLTable;
    $DB->TblName = 'shop_categories';
    $where['cat_id']['='] = $cid;
    $res = $DB->Select('cat_id,cat_name,cat_parent', $where);
    if($res !== false)
    {
        $pid = mysql_fetch_array($res);
        if($pid['cat_parent'] !== "0")
        {
           $fr[] = $pid['cat_id'];
           build_path($pid['cat_parent']);
        } else {
            $fr[] = $cid;
            $fr = array_reverse($fr);
            print_r($fr);
            return $fr;
        }
    }
}

print_r(build_path(100));

Why is working print_r in function, but second print_r returns NULL?

© Stack Overflow or respective owner

Related posts about php