Looping through an object with incremental property names using PHP

11 Views Asked by At

I am given a JSON object and I use json_decode() to get an object that looks like this. (just the first two properties)

object(stdClass)#2 (118) {
  ["Row_1_Column_1"]=>
  object(stdClass)#1 (8) {
    ["fontName"]=>
    string(5) "Times"
    ["fontSize"]=>
    string(3) "7.0"
    ["fontStyle"]=>
    string(4) "Bold"
    ["x"]=>
    string(6) "265.29"
    ["y"]=>
    string(5) "36.60"
    ["width"]=>
    string(5) "80.19"
    ["height"]=>
    string(4) "7.18"
    ["text"]=>
    string(19) "Sales Order - 73726"
  }
  ["Row_2_Column_1"]=>
  object(stdClass)#3 (7) {
    ["fontName"]=>
    string(5) "Times"
    ["fontSize"]=>
    string(3) "7.0"
    ["x"]=>
    string(6) "121.61"
    ["y"]=>
    string(5) "65.93"
    ["width"]=>
    string(5) "94.71"
    ["height"]=>
    string(4) "7.18"
    ["text"]=>
    string(23) "The Better Company"
  }

Both the row and the column number will increment How can I loop through an object with incremental properties? I normally would loop through an object like this:

foreach($jsonArray->row as $columns)
0

There are 0 best solutions below