I've now fixed the memory issue because I found a problem where the root element - 1 was linking to itself so I changed it to null. It now prints the right data except wherever there are child elements it doesn't print that element. So if p_id = 2 has 2 child elements p_id 2 itself won't appear in the array:

Code:
Array
(
    [2] => Array
        (
            [0] => stdClass Object
                (
                    [p_id] => 120
                    [c_id] => 2
                    [project_name] => Another project
                    [project_desc] => another project
                    [date_added] => 2012-01-01 00:00:00
                    [parent_id] => 2
                    [allocated_hrs] => 100
                    [date_from] => 2012-01-01 00:00:00
                    [date_to] => 2012-01-01 00:00:00
                    [status] => active
                    [priority] => 1
                    [completed] => 1
                    [author] => 271
                    [p_date_added] => 1st Jan 2012
                    [date_from_formatted] => 2012-01-01
                    [date_to_formatted] => 2012-01-01
                    [proj_id] => 120
                    [cust_name] => Customer 2
                    [cust_id] => 2
                )

        )

    [3] => stdClass Object
        (
            [p_id] => 3
            [c_id] => 2
            [project_name] => This is a project
            [project_desc] => This is a projectThis is a projectThis is a projectThis is a projectThis is a projectThis is a projectThis is a projectThis is a projectThis is a project
            [date_added] => 2012-03-28 09:27:16
            [parent_id] => 1
            [allocated_hrs] => 100
            [date_from] => 2012-10-10 00:00:00
            [date_to] => 2012-11-10 00:00:00
            [status] => active
            [priority] => 1
            [completed] => 0
            [author] => 271
            [p_date_added] => 28th Mar 2012
            [date_from_formatted] => 2012-10-10
            [date_to_formatted] => 2012-11-10
            [proj_id] => 3
            [cust_name] => Customer 2
            [cust_id] => 2
        )

)