循环对象(stdClass)

时间:2013-06-26 16:15:19

标签: php object

我看到了这个例子,但仍不确定如何去做它

问题在于他们将表格转换为列 - >行而不是行 - >在列中,您可以通过创建新表并反转列和行来完成此操作。

$table = array();

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

的print_r($表);

有些人可以协助我循环浏览这些数据,计划将数据显示为表格 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" 
        } 
    }
}

我在想这件事

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

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

1 个答案:

答案 0 :(得分:1)

试试这个:

foreach($result->result->complexObjectArray as $item){
    echo $item->increment_id;
}