dsoy71058 2013-06-26 16:15
浏览 118
已采纳

循环对象(stdClass)

I saw this exmaple but still not sure how to go about it

The problem is that they transposed the table into column -> row instead of row -> column, you can do that by creating a new table and reverse the columns and rows.

$table = array();

foreach ($result['xxx']->Columns->Column as $colnr => $coldata) {
    foreach ($coldata->Rows->string as $rownr => $rowdata) {
        $table[$rownr][$coldata->Name] = $rowdata;
    }
}

print_r($table);

Could some assist me on looping through this data , planning to display the data as table result with var_dump($result->result);

object(stdClass) #5 (1) { 
    ["complexObjectArray"]= > array(5) {
        [0] = > object(stdClass) #6 (105) { 
            ["increment_id"]= > string(9) "100000118" 
            ["store_id"] = > string(1) "1" 
            ["created_at"] = > string(19) "2013-04-21 07:14:34"
        }
        [1] = > object(stdClass) #7 (104) { 
            ["increment_id"]= > string(9) "100000128" 
            ["store_id"] = > string(1) "1" 
            ["created_at"] = > string(19) "2013-04-22 09:50:27" 
        }
        [2] = > object(stdClass) #8 (105) { 
            ["increment_id"]= > string(9) "100000133" 
            ["store_id"] = > string(1) "1" 
            ["created_at"] = > string(19) "2013-04-24 07:43:40" 
            ["updated_at"] = > string(19) "2013-04-27 14:50:23" 
        }
        [3] = > object(stdClass) #9 (108) { 
            ["increment_id"]= > string(9) "100000156" 
            ["store_id"] = > string(1) "1" 
            ["created_at"] = > string(19) "2013-05-07 14:41:30" 
        } 
    }
}

I was thinking of something around this

    foreach($result as $complexObj){
foreach($complexObj as $totalArray){
foreach($totalArray as $item){

echo $item->["increment_id"];
}
}
}
  • 写回答

1条回答 默认 最新

  • dongmo1708 2013-06-26 16:30
    关注

    Try this:

    foreach($result->result->complexObjectArray as $item){
        echo $item->increment_id;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?