title: PHP Nested foreach with Key
body: <p>I have been trying to work this out for two days now and am hitting a brick wall. I have a skyscanner array that has flight itineraries where I have the flight </p>
  
  <pre><code>Leg - being Itineraries -&gt; OutboundLegId - 
  </code></pre>
  
  <p>and also the legs which shows the flight number - being </p>
  
  <pre><code>Legs -&gt; FlightNumbers -&gt; FlightNumber.
  </code></pre>
  
  <p>What I am trying to achieve is to display the Itinerary and then join the Flight Number on to that. But no matter what I try I cannot get this to work. I have read all about Keys on here and tried loads of examples but am coming up with nothing. Can someone point me in the right direction please?</p>
  
  <p>Example arrays below</p>
  
  <pre><code>[Itineraries] =&gt; Array
  (
      [0] =&gt; Array
          (
              [OutboundLegId] =&gt; 13542-1610140610-29-0-13445-1610141240
              [InboundLegId] =&gt; 13445-1610211340-29-0-13542-1610211640
              [PricingOptions] =&gt; Array
                  (
                      [0] =&gt; Array
                          (
                              [Agents] =&gt; Array
                                  (
                                      [0] =&gt; 2174187
                                  )
  
                              [QuoteAgeInMinutes] =&gt; 31
                              [Price] =&gt; 200.98
                              [DeeplinkUrl] =&gt; http://partners.api.skyscanner.net/apiservices/deeplink/v2?_cje=5JlLCgyPUKY0hT8T0Ybh6dL0Xf0htAiHTFX7RU79eeI3XvrsxvEqP1QUJAoHiHRd&amp;url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fUK%2fen-gb%2fGBP%2fcook%2f2%2f13542.13445.2016-10-14%2c13445.13542.2016-10-21%2fair%2fairli%2fflights%3fitinerary%3dflight%7c-32294%7c1152%7c13542%7c2016-10-14T06%3a10%7c13445%7c2016-10-14T12%3a40%2cflight%7c-32294%7c1153%7c13445%7c2016-10-21T13%3a40%7c13542%7c2016-10-21T16%3a40%26carriers%3d-32294%26passengers%3d1%2c0%2c0%26channel%3ddataapi%26cabin_class%3deconomy%26facilitated%3dfalse%26ticket_price%3d200.98%26is_npt%3dfalse%26is_multipart%3dfalse%26client_id%3dskyscanner_b2b%26request_id%3d3bc96bda-fd7c-403a-b841-2ccc3c26071d%26commercial_filters%3dfalse%26q_datetime_utc%3d2016-09-29T08%3a18%3a27
                          )
  
  [Legs] =&gt; Array
  (
      [0] =&gt; Array
          (
              [Id] =&gt; 13542-1610140610-29-0-13445-1610141240
              [SegmentIds] =&gt; Array
                  (
                      [0] =&gt; 1
                  )
  
              [OriginStation] =&gt; 13542
              [DestinationStation] =&gt; 13445
              [Departure] =&gt; 2016-10-14T06:10:00
              [Arrival] =&gt; 2016-10-14T12:40:00
              [Duration] =&gt; 270
              [JourneyMode] =&gt; Flight
              [Stops] =&gt; Array
                  (
                  )
  
              [Carriers] =&gt; Array
                  (
                      [0] =&gt; 105
                  )
  
              [OperatingCarriers] =&gt; Array
                  (
                      [0] =&gt; 105
                  )
  
              [Directionality] =&gt; Outbound
              [FlightNumbers] =&gt; Array
                  (
                      [0] =&gt; Array
                          (
                              [FlightNumber] =&gt; 1152
                              [CarrierId] =&gt; 105
                          )
  
                  )
  
          )
  </code></pre>