dongtao9158 2014-01-12 20:39
浏览 75
已采纳

使用stdClass对象循环访问php数组

How do I loop through this array and get all the term_id's?

Array (
    [0] => stdClass Object (
        [term_id] => 43
    )
    [1] => stdClass Object (
        [term_id] => 25
    )
)
  • 写回答

2条回答 默认 最新

  • duanlu1950 2014-01-12 20:47
    关注
    $ob1 = new stdClass();
    $ob1->term_id = 43;
    
    $ob2 = new stdClass();
    $ob2->term_id = 25;
    
    $scope = array($ob1,$ob2);
    
    foreach($scope as $o){
      echo $o->term_id.'<br/>';
    }
    
    // Out
    // 43
    // 25
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?