title: Showing a search results page which has values from a multidimentional array in php
body: <p>I have this array </p>
  
  <pre><code>Array
  (
      [availableTrips] =&gt; Array
          (
              [AC] =&gt; false
              [arrivalTime] =&gt; 1830
              [availableSeats] =&gt; 4
              [boardingTimes] =&gt; Array
                  (
                      [bpId] =&gt; 460319
                      [bpName] =&gt;  Kalasipalyam 
                      [location] =&gt;  Kalasipalyam 
                      [prime] =&gt; false
                      [time] =&gt; 1215
                  )
  
              [busType] =&gt; Non A/C Semisleeper (2+2)
              [busTypeId] =&gt; 110
              [cancellationPolicy] =&gt; 0:8:100:0;8:24:50:0;24:-1:15:0
              [departureTime] =&gt; 1215
              [doj] =&gt; 2014-06-18T00:00:00+05:30
              [droppingTimes] =&gt; Array
                  (
                      [bpId] =&gt; 559663
                      [bpName] =&gt;  Mananthavaadi 
                      [location] =&gt;  Mananthavaadi 
                      [prime] =&gt; false
                      [time] =&gt; 390
                  )
  
              [fares] =&gt; 650
              [id] =&gt; 100102612640227182
              [idProofRequired] =&gt; false
              [nonAC] =&gt; true
              [operator] =&gt; 5127
              [partialCancellationAllowed] =&gt; false
              [routeId] =&gt; 100102600000227182
              [seater] =&gt; true
              [sleeper] =&gt; false
              [travels] =&gt; SKS Travels 
              [mTicketEnabled] =&gt; true
          )
  
  )
  </code></pre>
  
  <p>which I get as a response from an API of bus ticket booking service.This is a search result of a single bus I got for a particular source and destination.For other source destination pairs,the result will be something can be like,if there is more than one bus on the route.</p>
  
  <pre><code>Array
  (
      [availableTrips] =&gt; Array
          (
              [0] =&gt; Array         //1st bus in the search result
                  (
                      [AC] =&gt; true
                      [arrivalTime] =&gt; 1845
                      [availableSeats] =&gt; 28
                      [boardingTimes] =&gt; Array
                          (
                              [0] =&gt; Array
                                  (
                                      [bpId] =&gt; 46768
                                      [bpName] =&gt; Kalasipalyam Main Road
                                      [location] =&gt; Kalasipalyam Main Road
                                      [prime] =&gt; false
                                      [time] =&gt; 1260
                                  )
  
                              [1] =&gt; Array
                                  (
                                      [bpId] =&gt; 46774
                                      [bpName] =&gt; Christ University
                                      [location] =&gt; Christ University
                                      [prime] =&gt; false
                                      [time] =&gt; 1280
                                  )
  
                              [2] =&gt; Array
                                  (
                                      [bpId] =&gt; 46771
                                      [bpName] =&gt; Madiwala
                                      [location] =&gt; Madiwala
                                      [prime] =&gt; true
                                      [time] =&gt; 1305
                                  )
  
                              [3] =&gt; Array
                                  (
                                      [bpId] =&gt; 46776
                                      [bpName] =&gt; Electronic City Toll Gate
                                      [location] =&gt; Electronic City Toll Gate
                                      [prime] =&gt; false
                                      [time] =&gt; 1330
                                  )
  
                              [4] =&gt; Array
                                  (
                                      [bpId] =&gt; 46778
                                      [bpName] =&gt; Bommasandra Post Office
                                      [location] =&gt; Bommasandra Post Office
                                      [prime] =&gt; false
                                      [time] =&gt; 1340
                                  )
  
                              [5] =&gt; Array
                                  (
                                      [bpId] =&gt; 46779
                                      [bpName] =&gt; Attibele
                                      [location] =&gt; Attibele
                                      [prime] =&gt; false
                                      [time] =&gt; 1350
                                  )
  
                              [6] =&gt; Array
                                  (
                                      [bpId] =&gt; 46780
                                      [bpName] =&gt; Hosur
                                      [location] =&gt; Hosur
                                      [prime] =&gt; false
                                      [time] =&gt; 1360
                                  )
  
                          )
  
                      [busType] =&gt; Volvo Multiaxle A/C Seater Semi Sleeper (2+2)
                      [busTypeId] =&gt; 101
                      [cancellationPolicy] =&gt; 0:12:100:0;12:-1:10:0
                      [departureTime] =&gt; 1305
                      [doj] =&gt; 2014-06-18T00:00:00+05:30
                      [droppingTimes] =&gt; Array
                          (
                              [0] =&gt; Array
                                  (
                                      [bpId] =&gt; 46886
                                      [bpName] =&gt; Edapally Toll Gate
                                      [location] =&gt; Edapally Toll Gate
                                      [prime] =&gt; false
                                      [time] =&gt; 1825
                                  )
  
                              [1] =&gt; Array
                                  (
                                      [bpId] =&gt; 46884
                                      [bpName] =&gt; Palarivattam
                                      [location] =&gt; Palarivattam
                                      [prime] =&gt; false
                                      [time] =&gt; 1830
                                  )
  
                              [2] =&gt; Array
                                  (
                                      [bpId] =&gt; 46882
                                      [bpName] =&gt; Vytla junction
                                      [location] =&gt; Vytla junction
                                      [prime] =&gt; true
                                      [time] =&gt; 1845
                                  )
  
                              [3] =&gt; Array
                                  (
                                      [bpId] =&gt; 46972
                                      [bpName] =&gt; MG Road
                                      [location] =&gt; MG Road
                                      [prime] =&gt; false
                                      [time] =&gt; 1860
                                  )
  
                          )
  
                      [fares] =&gt; 1000.00
                      [id] =&gt; 200855412640007772
                      [idProofRequired] =&gt; false
                      [nonAC] =&gt; false
                      [operator] =&gt; 7478
                      [partialCancellationAllowed] =&gt; true
                      [routeId] =&gt; 200855400000007772
                      [seater] =&gt; true
                      [sleeper] =&gt; false
                      [travels] =&gt; Shama Transport
                      [mTicketEnabled] =&gt; true
                  )
  
              [1] =&gt; Array   //2nd bus in the search result
                  (
                      [AC] =&gt; true
                      [arrivalTime] =&gt; 1710
                      [availableSeats] =&gt; 33
                      [boardingTimes] =&gt; Array
                          (
                              [0] =&gt; Array
                                  (
                                      [bpId] =&gt; 34106
                                      [bpName] =&gt; Kalasipalyam Main Road
                                      [location] =&gt; Kalasipalyam Main Road
                                      [prime] =&gt; false
                                      [time] =&gt; 1080
                                  )
  
                              [1] =&gt; Array
                                  (
                                      [bpId] =&gt; 34099
                                      [bpName] =&gt; Dairy circle
                                      [location] =&gt; Dairy circle
                                      [prime] =&gt; false
                                      [time] =&gt; 1095
                                  )
  
                              [2] =&gt; Array
                                  (
                                      [bpId] =&gt; 34098
                                      [bpName] =&gt; Christ University
                                      [location] =&gt; Christ University
                                      [prime] =&gt; false
                                      [time] =&gt; 1100
                                  )
  
                              [3] =&gt; Array
                                  (
                                      [bpId] =&gt; 34093
                                      [bpName] =&gt; Madiwala
                                      [location] =&gt; Madiwala
                                      [prime] =&gt; true
                                      [time] =&gt; 1170
                                  )
  
                              [4] =&gt; Array
                                  (
                                      [bpId] =&gt; 34103
                                      [bpName] =&gt; Electronic City Toll Gate
                                      [location] =&gt; Electronic City Toll Gate
                                      [prime] =&gt; false
                                      [time] =&gt; 1185
                                  )
  
                              [5] =&gt; Array
                                  (
                                      [bpId] =&gt; 34109
                                      [bpName] =&gt; Narayana Hridayalaya
                                      [location] =&gt; Narayana Hridayalaya
                                      [prime] =&gt; false
                                      [time] =&gt; 1195
                                  )
  
                              [6] =&gt; Array
                                  (
                                      [bpId] =&gt; 34095
                                      [bpName] =&gt; Attibele
                                      [location] =&gt; Attibele
                                      [prime] =&gt; false
                                      [time] =&gt; 1200
                                  )
  
                              [7] =&gt; Array
                                  (
                                      [bpId] =&gt; 34114
                                      [bpName] =&gt; Bommasandra Post Office
                                      [location] =&gt; Bommasandra Post Office
                                      [prime] =&gt; false
                                      [time] =&gt; 1210
                                  )
  
                              [8] =&gt; Array
                                  (
                                      [bpId] =&gt; 34112
                                      [bpName] =&gt; Hosur
                                      [location] =&gt; Hosur
                                      [prime] =&gt; false
                                      [time] =&gt; 1215
                                  )
  
                          )
  
                      [busType] =&gt; Volvo Multiaxle A/C Seater Semi Sleeper (2+2)
                      [busTypeId] =&gt; 101
                      [cancellationPolicy] =&gt; 0:12:100:0;12:-1:10:0
                      [departureTime] =&gt; 1170
                      [doj] =&gt; 2014-06-18T00:00:00+05:30
                      [droppingTimes] =&gt; Array
                          (
                              [bpId] =&gt; 45746
                              [bpName] =&gt; Vytala Bye Pass
                              [location] =&gt; Vyttila
                              [prime] =&gt; true
                              [time] =&gt; 1710
                          )
  
                      [fares] =&gt; 1100.00
                      [id] =&gt; 200855412640007290
                      [idProofRequired] =&gt; false
                      [nonAC] =&gt; false
                      [operator] =&gt; 6708
                      [partialCancellationAllowed] =&gt; true
                      [routeId] =&gt; 200855400000007290
                      [seater] =&gt; true
                      [sleeper] =&gt; false
                      [travels] =&gt; Atlas Travels
                      [mTicketEnabled] =&gt; true
                  )
  </code></pre>
  
  <p>This goes on and on depending on the number of results.</p>
  
  <p>This is the part of code which outputs the results above.</p>
  
  <pre><code>$availableBuses = json_decode($availableTrips,true);
  
              echo "&lt;pre&gt;";
              print_r($availableBuses);
              echo "&lt;/pre&gt;";  
  </code></pre>
  
  <p>Now what I am trying to do is,to loop and parse through this array output the results into some div like.</p>
  
  <pre><code>&lt;h1&gt;Search results &lt;/h1&gt;
  &lt;div&gt;Bus name:&lt;?php echo $ availableBuses['availableTrips']['travels'];?&gt;Boarding place:&lt;?php echo $availableBuses['availableTrips']['boradingTimes']['location']&lt;/div&gt;
  </code></pre>
  
  <p>THe above will look like</p>
  
  <pre><code>**Search Results**
  Bus name : SKS Travels
  Boarding place : Kalasipalyam
  </code></pre>
  
  <p>if there are more results the above will be repeated as</p>
  
  <pre><code>         **Search Results**
          Bus name : SKS Travels
          Boarding place : Kalasipalyam
  
          Bus name : 1 Travels
          Boarding place : place 1
  
          Bus name : 2 Travels
          Boarding place : place 2 
  .......
  </code></pre>
  
  <p>Im unable to parse this complex array properly</p>
  
  <p>I have tried</p>
  
  <pre><code> $jsonIterator = new RecursiveIteratorIterator(
           new RecursiveArrayIterator(json_decode($availableTrips, TRUE)),
           RecursiveIteratorIterator::SELF_FIRST);
           foreach( $jsonIterator as $output)
                   {
              echo $output['travels'];
                      echo $output['droppingTimes']['location'];
                }
  </code></pre>
  
  <p>But I couldnt get what I wanted.I want to repeats the div with appropriate contents as the number of bus increase.</p>
  
  <p>**I know this can be some dumb questions around,but Im finding it really hard to get through nor google did helped.If someone here could help me will be of great help</p>
  
  <p>Thanks.</p>
  
  <p><strong>Please excuse the long question,didnt find another way to explain this.</strong></p>