从数组中获取值

时间:2012-11-16 21:55:30

标签: php arrays

如果我有一个类似下面的数组,那么从数组中获取所有ListingCategory项的最佳方法是什么,所以我可以在foreach中的if语句中使用它们?

阵列:

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

1 个答案:

答案 0 :(得分:3)

这将遍历所有数组项以及每个ListingCategory中的所有子项。

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