Jess McKenzie
Jess McKenzie

Reputation: 8385

Getting a value out of an array

If I have an array like the one below what would be the best way to get all of the ListingCategory items out of the array so I can use them in an if statement within a foreach?

Array:

Array ( 
    [0] => Array ( 
        [ListingId] => SimpleXMLElement Object ([0] => 532712629) 
        [ListingCategory] => SimpleXMLElement Object ( [0] => 0350-5748-3400- ) 
    ) [1] =>

Upvotes: 1

Views: 59

Answers (1)

Jordan Mack
Jordan Mack

Reputation: 8733

This will cycle through all array items, and all of the children within each ListingCategory.

foreach($array as $item)
{
    foreach($item["ListingCategory"]->children() as $val)
    {
        doSomething($val);
    }
}

Upvotes: 3

Related Questions