0

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"];
}
}
}
CodeGuru
  • 3,645
  • 14
  • 55
  • 99

1 Answers1

1

Try this:

foreach($result->result->complexObjectArray as $item){
    echo $item->increment_id;
}
keithhatfield
  • 3,273
  • 1
  • 17
  • 24
  • not showing anything , even var_dump($item). I'm looking at http://stackoverflow.com/questions/950827/stdclass-object-and-foreach-loops it seems very similar to my issue , i'm trying to understand it :( – CodeGuru Jun 26 '13 at 16:40
  • @RainbowHat If `var_dump($result)` produces the dump you have above, then this should work. Try doing a `var_dump($result->complexObjectArray)` before the loop ... that should display the array that you're wanting to loop over. If it doesn't, then `$result` is not in the structure you posted above – keithhatfield Jun 26 '13 at 17:28
  • It says NULL var_dump($result->complexObjectArray) before loop – CodeGuru Jun 26 '13 at 17:55
  • Then `$result` does not contain the dump you provided above. What variable is the dump from? What do you get when you dump `$result`? – keithhatfield Jun 26 '13 at 18:13
  • Above is actually var_dump($result->result); sorry :x – CodeGuru Jun 26 '13 at 18:16
  • var_dump($result); will give additional code(at the very front) object(stdClass)#4 (1) { ["result"]=> – CodeGuru Jun 26 '13 at 18:17
  • var_dump($result->result->complexObjectArray); will give me array(5) { [0]=> object(stdClass)#6 (105) { ["increment_id"]=> string(9) "100000118" etc – CodeGuru Jun 26 '13 at 18:20
  • I have updated the loop above to account for the variable structure. Give that a shot ... – keithhatfield Jun 26 '13 at 18:26
  • Yap, I figured it out, Thank you ! I believe i can now display it like a table. Thank you so much @dleiftah , so nice of you. I learnt something important today (Y) – CodeGuru Jun 26 '13 at 18:28