首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >遍历对象(StdClass)

遍历对象(StdClass)
EN

Stack Overflow用户
提问于 2013-06-27 00:15:19
回答 1查看 300关注 0票数 0

我看过这个例子,但还是不知道该怎么做。

问题是他们将表转置为列->行,而不是行->列,您可以通过创建一个新表并颠倒列和行来做到这一点。

代码语言:javascript
复制
$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);

是否可以帮助我遍历这些数据,计划使用var_dump($ result ->result)将数据显示为表结果;

代码语言:javascript
复制
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" 
        } 
    }
}

我在想一些关于这个的东西

代码语言:javascript
复制
    foreach($result as $complexObj){
foreach($complexObj as $totalArray){
foreach($totalArray as $item){

echo $item->["increment_id"];
}
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-27 00:30:03

试试这个:

代码语言:javascript
复制
foreach($result->result->complexObjectArray as $item){
    echo $item->increment_id;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17325329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档