Page 1 of 1

problem returning array in a function

Posted: Sun May 25, 2008 10:17 pm
by scheinarts
Hey guys,

I have a function the gets some data from a DOM object but I cant seem the put it all in array to return that array object.

Code: Select all

    function runQuery()
    {
        
        foreach ($venues as $venue)
        {
            $names = $venue->getElementsByTagName('name');
            $contacts = $venue->getElementsByTagName('contact_link');
            
            foreach ($contacts as $contact)
            {
                $contact = getContact($contact->getAttribute('href'));
                $venueItem['contact_info'] = $contact;
            }
            
            foreach ($names as $name)
            {
                $venueItem['name'] = $name->nodeValue;
                
                if($name->getAttribute('href') != NULL)
                {
                    $address = getAddress($name->getAttribute('href'));
                }
                else
                {
                    $address = getAddress($contact['link']);
                }
                $venueItem['address_info'] = $address;
            }
            
            $venueData['item'] = $venueItem;
        }
    
        return $venueData;
    }
I excluded some variables that go before the for loop since they are not relevant to my question. If I print $venueData inside the for loop it works perfect. But if I do the following then I get nothing when printing it.

Code: Select all

$query = runQuery();
print_r($query);
And I need to be able to loop through the $query object, but it seems to be empty. What can I do here ?
Many thanks!

Re: problem returning array in a function

Posted: Mon May 26, 2008 10:21 am
by pickle
Print out $venueData at various points in your function to see that it's being built properly.

Also, please wrap your PHP code in [syntax=php][/syntax] tags, not the default [syntax=php][/syntax]

Re: problem returning array in a function

Posted: Wed May 28, 2008 12:10 am
by scheinarts
Never figured out what the problem, so I just winded up recoding the function and other functions in the app. Thanks though!

I dont see the difference in the code tags???

Re: problem returning array in a function

Posted: Wed May 28, 2008 3:10 pm
by pickle
There - I've disabled BBCode parsing on my previous post. Sorry about that.

Re: problem returning array in a function

Posted: Wed May 28, 2008 3:36 pm
by John Cartwright
hint, $venues was never defined/passed to the function