Welcome Guest, Not a member yet? Register   Sign In
Adding property to an object
#2

[eluser]Phil Sturgeon[/eluser]
Code:
function find_ ($page_id)
    {
        $this->db->where('page_parent_id', $page_id);
        $this->db->order_by('page_created', 'DESC');
        $query = $this->db->get('fala_pages');
        
        foreach ($query->result() as &$row)
        {
            $row->subpages = count( $this->find_($row->page_id) );
        }
        
        return $query->result();
    }

Notice the & before the $row in your foreach. This means the $row is passed by refference and not by value, meaning you can modify that variable and change the original value.


Messages In This Thread
Adding property to an object - by El Forum - 03-16-2009, 09:35 AM
Adding property to an object - by El Forum - 03-16-2009, 09:39 AM
Adding property to an object - by El Forum - 03-16-2009, 09:41 AM
Adding property to an object - by El Forum - 03-16-2009, 09:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB