title: Read an array of data to insert into a datatable
body: <p>I have an array which contains train departure data. What I am trying to do is loop through the array
  and insert each record into a database.</p>
  <p>The issue is when I read the array I am only getting one record. Where am I going wrong?</p>
  <p>My code:</p>
  <pre><code>$data = array();
  require(&quot;OpenLDBWS.php&quot;);
      $OpenLDBWS = new OpenLDBWS(&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;);
      $response = $OpenLDBWS-&gt;GetDepartureBoard(20,&quot;GLC&quot;,0,0,30,120); 
      foreach($response-&gt;GetStationBoardResult-&gt;trainServices-&gt;service as $service)
      {
          foreach ($response as $value) {
                  foreach ($value as $key =&gt; $val) {
                  // insert records in to database
              }
      }
  </code></pre>
  <p>The array of data I am working with:</p>
  <pre><code>stdClass Object ( [GetStationBoardResult] =&gt; stdClass Object ( [generatedAt] =&gt; 2021-07-08T19:12:29.7123685+01:00 [locationName] =&gt; Glasgow Central [crs] =&gt; GLC [platformAvailable] =&gt; 1 [trainServices] =&gt; stdClass Object ( [service] =&gt; Array ( [0] =&gt; stdClass Object ( [std] =&gt; 19:45 [etd] =&gt; On time [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; EcerPly59dqz5Om5WptKdA== [rsid] =&gt; SR961200 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Glasgow Central [crs] =&gt; GLC ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Largs [crs] =&gt; LAR ) ) ) ) [1] =&gt; stdClass Object ( [std] =&gt; 19:45 [etd] =&gt; On time [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; R8WIwBKrr5VG44stUZ1UEA== [rsid] =&gt; SR941100 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Glasgow Central [crs] =&gt; GLC ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Newton [crs] =&gt; NTN [via] =&gt; via Maxwell Park ) ) ) ) [2] =&gt; stdClass Object ( [std] =&gt; 19:46 [etd] =&gt; On time [platform] =&gt; 17 [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; L7/E80Ta2f6z2qCI/YGTJg== [rsid] =&gt; SR693100 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Larkhall [crs] =&gt; LRH ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Dalmuir [crs] =&gt; DMR [via] =&gt; via Yoker ) ) ) ) [3] =&gt; stdClass Object ( [std] =&gt; 19:47 [etd] =&gt; On time [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; xnijYlYcM+E5zxGOlHLnkQ== [rsid] =&gt; SR907300 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Glasgow Central [crs] =&gt; GLC ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; East Kilbride [crs] =&gt; EKL ) ) ) ) [4] =&gt; stdClass Object ( [std] =&gt; 19:47 [etd] =&gt; On time [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; XGSOnG/rY0DfEAgniUKkVQ== [rsid] =&gt; SR757800 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Glasgow Central [crs] =&gt; GLC ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Edinburgh [crs] =&gt; EDB [via] =&gt; via Motherwell ) ) ) ) [5] =&gt; stdClass Object ( [std] =&gt; 19:48 [etd] =&gt; On time [platform] =&gt; 16 [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; X05hqJA8cAN3NrPewryo6Q== [rsid] =&gt; SR933700 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Dalmuir [crs] =&gt; DMR ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Larkhall [crs] =&gt; LRH ) ) ) ) [6] =&gt; stdClass Object ( [std] =&gt; 19:50 [etd] =&gt; On time [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; c+c8//o7sx5YQ26GzaHi1g== [rsid] =&gt; SR838900 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Glasgow Central [crs] =&gt; GLC ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Lanark [crs] =&gt; LNK [via] =&gt; via Bellshill &amp; Shieldmuir ) ) ) ) [7] =&gt; stdClass Object ( [std] =&gt; 19:55 [etd] =&gt; Cancelled [operator] =&gt; ScotRail [operatorCode] =&gt; SR [isCancelled] =&gt; 1 [serviceType] =&gt; train [cancelReason] =&gt; This train has been cancelled because of a member of on train staff being taken ill [serviceID] =&gt; cM9u9ORpWdmTiCN8EAGXXQ== [rsid] =&gt; SR688800 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Motherwell [crs] =&gt; MTH ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Dalmuir [crs] =&gt; DMR [via] =&gt; via Singer ) ) ) ) [8] =&gt; stdClass Object ( [std] =&gt; 19:56 [etd] =&gt; On time [platform] =&gt; 16 [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; kzwZwDbuOKlSwgIIPDDElQ== [rsid] =&gt; SR686100 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Dalmuir [crs] =&gt; DMR ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Cumbernauld [crs] =&gt; CUB ) ) ) ) [9] =&gt; stdClass Object ( [std] =&gt; 20:04 [etd] =&gt; On time [platform] =&gt; 17 [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; VoJk6LX+awhqYOqp6cnI2Q== [rsid] =&gt; SR704600 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Motherwell [crs] =&gt; MTH ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Dalmuir [crs] =&gt; DMR [via] =&gt; via Yoker ) ) ) ) [10] =&gt; stdClass Object ( [std] =&gt; 20:06 [etd] =&gt; On time [operator] =&gt; Avanti West Coast [operatorCode] =&gt; VT [serviceType] =&gt; train [serviceID] =&gt; pauq/9t8+GHiHdFzZDn62A== [rsid] =&gt; VT184000 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Glasgow Central [crs] =&gt; GLC ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Crewe [crs] =&gt; CRE ) ) ) ) [11] =&gt; stdClass Object ( [std] =&gt; 20:06 [etd] =&gt; On time [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; 8znnX8RPY+CaRTj2O3p2vA== [rsid] =&gt; SR868100 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Glasgow Central [crs] =&gt; GLC ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Gourock [crs] =&gt; GRK ) ) ) ) [12] =&gt; stdClass Object ( [std] =&gt; 20:12 [etd] =&gt; On time [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; V+ACg5jRw9iq080tsvBYWg== [rsid] =&gt; SR854200 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Glasgow Central [crs] =&gt; GLC ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Paisley Canal [crs] =&gt; PCN ) ) ) ) [13] =&gt; stdClass Object ( [std] =&gt; 20:16 [etd] =&gt; On time [platform] =&gt; 17 [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; 3CyYihwXPPP94DDmL/a+Cw== [rsid] =&gt; SR933500 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Larkhall [crs] =&gt; LRH ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Garscadden [crs] =&gt; GRS ) ) ) ) [14] =&gt; stdClass Object ( [std] =&gt; 20:17 [etd] =&gt; On time [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; gAaRB1xr340a7MW8kiHUfw== [rsid] =&gt; SR313400 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Glasgow Central [crs] =&gt; GLC ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Ardrossan Harbour [crs] =&gt; ADS ) ) ) ) [15] =&gt; stdClass Object ( [std] =&gt; 20:17 [etd] =&gt; On time [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; 393KsY/5uadLhA0fNSmuPw== [rsid] =&gt; SR321700 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Glasgow Central [crs] =&gt; GLC ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Edinburgh [crs] =&gt; EDB [via] =&gt; via Shotts ) ) ) ) [16] =&gt; stdClass Object ( [std] =&gt; 20:17 [etd] =&gt; On time [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; lb/oSCEuOwwl8ywlZKj5CA== [rsid] =&gt; SR749000 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Glasgow Central [crs] =&gt; GLC ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Kilmarnock [crs] =&gt; KMK ) ) ) ) [17] =&gt; stdClass Object ( [std] =&gt; 20:18 [etd] =&gt; On time [platform] =&gt; 16 [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; ecekVrFi8Q4lzexOGa0mHA== [rsid] =&gt; SR694600 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Dalmuir [crs] =&gt; DMR ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Larkhall [crs] =&gt; LRH ) ) ) ) [18] =&gt; stdClass Object ( [std] =&gt; 20:25 [etd] =&gt; On time [platform] =&gt; 17 [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; wambmHj4esQVxzRmyf53+w== [rsid] =&gt; SR689000 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Cumbernauld [crs] =&gt; CUB ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Dalmuir [crs] =&gt; DMR [via] =&gt; via Yoker ) ) ) ) [19] =&gt; stdClass Object ( [std] =&gt; 20:28 [etd] =&gt; On time [platform] =&gt; 16 [operator] =&gt; ScotRail [operatorCode] =&gt; SR [serviceType] =&gt; train [serviceID] =&gt; 6BHc1ySAKVZ6rODADfEKOQ== [rsid] =&gt; SR847000 [origin] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Dalmuir [crs] =&gt; DMR ) ) ) [destination] =&gt; stdClass Object ( [location] =&gt; Array ( [0] =&gt; stdClass Object ( [locationName] =&gt; Motherwell [crs] =&gt; MTH ) ) ) ) ) ) ) )
  </code></pre>