I've the following PHP code with nested structures
<?php
$theJson = <<<EOF
{
  "date": 1492804820000,
  "node1": [{
    "id": 57163,
    "node1_description": "The node1 description",
    "node2": [{
      "id": 57163,
      "node2_description": "The node2 description",
      "dipartments": [{
        "id": 57163,
        "dip_description": "The dipartment description",
        "colorCods": [{
                    "id": 1,
                    "description": "Red",
                    "numbers": {
                        "num1": 1,
            "num2": 23,
            "num3": 11
                    }
                }, {
          "id": 2,
                    "description": "Yellow",
                    "numbers": {
                        "num1": 3,
            "num2": 45,
            "num3": 33
                    }
                }, {
          "id": 3,
                    "description": "Green",
                    "numbers": {
                        "num1": 31,
            "num2": 453,
            "num3": 323
                    }
                }, {
          "id": 3,
                    "description": "White",
                    "numbers": {
                        "num1": 3,
            "num2": 4,
            "num3": 3
                    }
                }]
      },
      {
        "id": 57345,
        "dip_description": "The dipartment description 2",
        "colorCods": [{
          "id": 1,
          "description": "Red",
          "numbers": {
            "num1": 4,
            "num2": 243,
            "num3": 151
          }
        }, {
          "id": 2,
          "description": "Yellow",
          "numbers": {
            "num1": 33,
            "num2": 415,
            "num3": 3
          }
        }, {
          "id": 3,
          "description": "Green",
          "numbers": {
            "num1": 331,
            "num2": 43,
            "num3": 33
          }
        }, {
          "id": 3,
          "description": "White",
          "numbers": {
            "num1": 32,
            "num2": 42,
            "num3": 33
          }
        }]
      }
    ]
    }]
  }]
}
EOF;
  $theArray = json_decode($theJson, true);
  foreach ($theArray['node1'] as $node1) {
          echo "Node 1 description :".$node1['node1_description'];
          echo "\n";
          echo "\n";
                foreach ($node1['node2'] as $node2) {
                        echo "Node 2 description :".$node2['node2_description'];
                        echo "\n";
                        echo "\n";
                                foreach ($node2['dipartments'] as $dip) {
                                                echo "Dipartment description: ".$dip['dip_description'];
                                                echo "\n";
                                                echo "\n";
                                                foreach ($dip['colorCods'] as $colCod) {
                                                          echo "Cod: ".$colCod['description'];
                                                          echo " - ";
                                                                echo "Number: ".$colCod['numbers']['num1'];
                                                                echo "\n";
                                                                echo "\n";
                                                }
                                }
                }
  }
?>
I need to extract the "num*" values from my JSON.
My code works fine, but it seems that the nested "for" cycles might not be the most efficient way to extract the "num*" values from my JSON.
Alternatives or samples?
 
     
     
    