2013-06-26 133 views
0

我看到這個〔實施例,但仍然不知道如何去了解它通過對象循環(stdClass的)

的問題是,他們調換表中插入列 - >行而不是行 - >列,你可以做通過創建一個新表並反轉列和行。

$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)的結果;

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" 
     } 
    } 
} 

我在想東西解決此

+0

@dleiftah感謝格式化,我盤算如何做到這一點:X – CodeGuru

回答

1

試試這個:

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

沒有顯示任何東西,甚至var_dump($ item)。我看着http://stackoverflow.com/questions/950827/stdclass-object-and-foreach-loops它看起來非常類似於我的問題,我試圖理解它:( – CodeGuru

+0

@RainbowHat如果'var_dump( $ result)'產生上面的轉儲,然後這個應該可以工作,試着在循環前做一個'var_dump($ result-> complexObjectArray)'來顯示你想要循環的數組。它沒有,那麼'$ result'不在你上面​​發佈的結構中 – keithhatfield

+0

它在循環前面說NULL NULL var_dump($ result-> complexObjectArray) – CodeGuru