0

请问一个基本的问题。有人可以帮助我获得所有三个主要类别字符串(要做的事情、交通和生活)。我只发现了如何单独获取它们

$categories[0]->maincategory;

但我怎样才能得到这三个?最好的感谢!

Array
(
[0] => stdClass Object
    (
        [id] => 2
        [maincategory] => Things to Do
        [category] => Activities and  Attractions
    )

[1] => stdClass Object
    (
        [id] => 6
        [maincategory] => Transportation
        [category] => Airport Transfers
    )

[2] => stdClass Object
    (
        [id] => 11
        [maincategory] => Living
        [category] => Broadband Internet
    )
)
4

2 回答 2

2

就像是

foreach ($stdClass as $sclass){
    if(!is_array($sclass)){
     echo $sclass.' ';
     }else{
    foreach ($sclass as $scl){


    echo $scl.' ';
    }
    }

    }
于 2013-10-24T08:11:47.290 回答
0

简单foreach的循环就可以了。

foreach ($categories as $category) {
  echo $category->maincategory;
}
于 2013-10-24T08:28:07.560 回答