title: Output nested JSON array in PHP
body: <p>When I run my PHP script, it generates the JSON that appears below.</p>
  
  <p>Most events happen on the same date but you'll notice that the Kevin Bridges performance has a different array structure to the rest, because there are multiple dates for him.</p>
  
  <p>I'd like to have a <code>foreach</code> loop list all those event dates individually, so ultimately I have an unordered list showing all event dates (including nested ones).</p>
  
  <p><strong>PHP:</strong></p>
  
  <pre><code>$json_link = "https://graph.facebook.com/{$fb_page_id}/events/attending/?fields={$fields}&amp;access_token={$access_token}&amp;since={$since}&amp;limit={$limit}";
  $json = file_get_contents($json_link);
  $arr = json_decode($json);
  var_dump($arr);
  </code></pre>
  
  <p><strong>JSON (contents of var_dump($arr):</strong></p>
  
  <pre><code>object(stdClass)#1 (2) {
    ["data"]=&gt;
    array(6) {
      [0]=&gt;
      object(stdClass)#2 (3) {
        ["name"]=&gt;
        string(25) "Professor Brian Cox Live!"
        ["start_time"]=&gt;
        string(24) "2019-02-19T18:00:00+0000"
        ["id"]=&gt;
        string(15) "844836785694139"
      }
      [1]=&gt;
      object(stdClass)#3 (3) {
        ["name"]=&gt;
        string(11) "Deacon Blue"
        ["start_time"]=&gt;
        string(24) "2018-12-15T18:00:00+0000"
        ["id"]=&gt;
        string(16) "1906293969624796"
      }
      [2]=&gt;
      object(stdClass)#4 (3) {
        ["name"]=&gt;
        string(25) "The Australian Pink Floyd"
        ["start_time"]=&gt;
        string(24) "2018-12-01T18:00:00+0000"
        ["id"]=&gt;
        string(15) "992095460928258"
      }
      [3]=&gt;
      object(stdClass)#5 (3) {
        ["name"]=&gt;
        string(30) "Jeff Wayne's War of the Worlds"
        ["start_time"]=&gt;
        string(24) "2018-11-30T18:00:00+0000"
        ["id"]=&gt;
        string(15) "127293857967359"
      }
      [4]=&gt;
      object(stdClass)#6 (3) {
        ["name"]=&gt;
        string(12) "Nitro Circus"
        ["start_time"]=&gt;
        string(24) "2018-11-21T18:00:00+0000"
        ["id"]=&gt;
        string(16) "1922897747961465"
      }
      [5]=&gt;
      object(stdClass)#7 (4) {
        ["event_times"]=&gt;
        array(17) {
          [0]=&gt;
          object(stdClass)#8 (4) {
            ["id"]=&gt;
            string(16) "1162283923902012"
            ["start_time"]=&gt;
            string(24) "2018-10-25T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-25T22:30:00+0100"
          }
          [1]=&gt;
          object(stdClass)#9 (4) {
            ["id"]=&gt;
            string(16) "1162283920568679"
            ["start_time"]=&gt;
            string(24) "2018-10-28T18:30:00+0000"
            ["end_time"]=&gt;
            string(24) "2018-10-28T22:30:00+0000"
          }
          [2]=&gt;
          object(stdClass)#10 (4) {
            ["id"]=&gt;
            string(16) "1162178570579214"
            ["start_time"]=&gt;
            string(24) "2018-10-27T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-27T22:30:00+0100"
          }
          [3]=&gt;
          object(stdClass)#11 (4) {
            ["id"]=&gt;
            string(16) "1162178567245881"
            ["start_time"]=&gt;
            string(24) "2018-10-26T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-26T22:30:00+0100"
          }
          [4]=&gt;
          object(stdClass)#12 (4) {
            ["id"]=&gt;
            string(16) "1162150737248664"
            ["start_time"]=&gt;
            string(24) "2018-10-21T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-21T22:30:00+0100"
          }
          [5]=&gt;
          object(stdClass)#13 (4) {
            ["id"]=&gt;
            string(16) "1161763073954097"
            ["start_time"]=&gt;
            string(24) "2018-10-17T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-17T22:30:00+0100"
          }
          [6]=&gt;
          object(stdClass)#14 (4) {
            ["id"]=&gt;
            string(16) "1161763070620764"
            ["start_time"]=&gt;
            string(24) "2018-10-18T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-18T22:30:00+0100"
          }
          [7]=&gt;
          object(stdClass)#15 (4) {
            ["id"]=&gt;
            string(16) "1161179750679096"
            ["start_time"]=&gt;
            string(24) "2018-10-20T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-20T22:30:00+0100"
          }
          [8]=&gt;
          object(stdClass)#16 (4) {
            ["id"]=&gt;
            string(16) "1161179747345763"
            ["start_time"]=&gt;
            string(24) "2018-10-19T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-19T22:30:00+0100"
          }
          [9]=&gt;
          object(stdClass)#17 (4) {
            ["id"]=&gt;
            string(16) "1161070534023351"
            ["start_time"]=&gt;
            string(24) "2018-10-07T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-07T22:30:00+0100"
          }
          [10]=&gt;
          object(stdClass)#18 (4) {
            ["id"]=&gt;
            string(16) "1161070530690018"
            ["start_time"]=&gt;
            string(24) "2018-10-14T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-14T22:30:00+0100"
          }
          [11]=&gt;
          object(stdClass)#19 (4) {
            ["id"]=&gt;
            string(16) "1160256300771441"
            ["start_time"]=&gt;
            string(24) "2018-10-13T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-13T22:30:00+0100"
          }
          [12]=&gt;
          object(stdClass)#20 (4) {
            ["id"]=&gt;
            string(16) "1160256287438109"
            ["start_time"]=&gt;
            string(24) "2018-10-05T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-05T22:30:00+0100"
          }
          [13]=&gt;
          object(stdClass)#21 (4) {
            ["id"]=&gt;
            string(16) "1160256284104776"
            ["start_time"]=&gt;
            string(24) "2018-10-04T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-04T22:30:00+0100"
          }
          [14]=&gt;
          object(stdClass)#22 (4) {
            ["id"]=&gt;
            string(16) "1160256280771443"
            ["start_time"]=&gt;
            string(24) "2018-10-06T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-06T22:30:00+0100"
          }
          [15]=&gt;
          object(stdClass)#23 (4) {
            ["id"]=&gt;
            string(16) "1160256277438110"
            ["start_time"]=&gt;
            string(24) "2018-10-12T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-12T22:30:00+0100"
          }
          [16]=&gt;
          object(stdClass)#24 (4) {
            ["id"]=&gt;
            string(16) "1160256274104777"
            ["start_time"]=&gt;
            string(24) "2018-10-11T18:30:00+0100"
            ["end_time"]=&gt;
            string(24) "2018-10-11T22:30:00+0100"
          }
        }
        ["name"]=&gt;
        string(13) "Kevin Bridges"
        ["start_time"]=&gt;
        string(24) "2018-10-04T18:30:00+0100"
        ["id"]=&gt;
        string(16) "1160256267438111"
      }
    }
  }
  </code></pre>
  
  <p>My code for looping is the following, however it doesn't loop through all the individual Kevin Bridges performances:</p>
  
  <p><strong>PHP:</strong></p>
  
  <pre><code>foreach (array_reverse($arr-&gt;data) as $key =&gt; $event):
  
      echo $event-&gt;id;
      echo $event-&gt;name;
      echo $event-&gt;start_time;
      echo '&lt;br&gt;';
  
  endforeach;
  </code></pre>