title: Get array element having highest date time value from a multidimensional array
body: <p>I have a array like this </p>
  
  <pre><code>Array
  (
      [4621162015] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [itemId] =&gt; 220929621668
                      [itemName] =&gt; Teak Protector - 1ltr water-based teak wood protector - maintain honey colour!
                      [itemPrice] =&gt; 24.99
                      [itemCurrencySign] =&gt; £
                      [itemGalleryUrl] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/qI8AAOSwt7pXMKHB/$_1.JPG?set_id=880000500F
                      [itemImages] =&gt; Array
                          (
                              [0] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/qI8AAOSwt7pXMKHB/$_1.JPG?set_id=880000500F
                              [1] =&gt; http://i.ebayimg.com/00/s/MTEzMVgxNjAw/z/70cAAOSwcL5XMKC6/$_1.JPG?set_id=880000500F
                          )
  
                      [itemQuantity] =&gt; 257
                      [itemStartTime] =&gt; 2012-01-10T16:40:03.000Z
                      [itemEndTime] =&gt; 2017-02-12T16:40:03.000Z
                      [itemUrl] =&gt; http://www.ebay.com/itm/Teak-Protector-1ltr-water-based-teak-wood-protector-maintain-honey-colour-/220929621668
                      [itemCategoryId] =&gt; 4621162015
                      [itemCategoryUrl] =&gt; http://stores.ebay.co.uk/JATI-Teak-and-Woven-Furniture/_i.html?_fsub=4621162015
                  )
  
              [1] =&gt; Array
                  (
                      [itemId] =&gt; 220929626118
                      [itemName] =&gt; Teak Patinizer - 1ltr patinizer to maintain the silver-patina or weathered look!
                      [itemPrice] =&gt; 24.99
                      [itemCurrencySign] =&gt; £
                      [itemGalleryUrl] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/1bwAAOSwYmZXMKE-/$_1.JPG?set_id=880000500F
                      [itemImages] =&gt; Array
                          (
                              [0] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/1bwAAOSwYmZXMKE-/$_1.JPG?set_id=880000500F
                              [1] =&gt; http://i.ebayimg.com/00/s/MTEzMVgxNjAw/z/A~4AAOSwubRXMKE8/$_1.JPG?set_id=880000500F
                          )
  
                      [itemQuantity] =&gt; 202
                      [itemStartTime] =&gt; 2012-01-10T16:49:41.000Z
                      [itemEndTime] =&gt; 2017-02-12T16:49:41.000Z
                      [itemUrl] =&gt; http://www.ebay.com/itm/Teak-Patinizer-1ltr-patinizer-maintain-silver-patina-weathered-look-/220929626118
                      [itemCategoryId] =&gt; 4621162015
                      [itemCategoryUrl] =&gt; http://stores.ebay.co.uk/JATI-Teak-and-Woven-Furniture/_i.html?_fsub=4621162015
                  )
  
              [2] =&gt; Array
                  (
                      [itemId] =&gt; 220929631080
                      [itemName] =&gt; Teak Cleaner - 1ltr bring back the original colour of new teak/hardwood!
                      [itemPrice] =&gt; 19.5
                      [itemCurrencySign] =&gt; £
                      [itemGalleryUrl] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/HWIAAOSw8vZXMKGK/$_1.JPG?set_id=880000500F
                      [itemImages] =&gt; Array
                          (
                              [0] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/HWIAAOSw8vZXMKGK/$_1.JPG?set_id=880000500F
                              [1] =&gt; http://i.ebayimg.com/00/s/MTEzMVgxNjAw/z/u8kAAOSw3mpXMKGT/$_1.JPG?set_id=880000500F
                          )
  
                      [itemQuantity] =&gt; 204
                      [itemStartTime] =&gt; 2012-01-10T16:59:50.000Z
                      [itemEndTime] =&gt; 2017-02-12T16:59:50.000Z
                      [itemUrl] =&gt; http://www.ebay.com/itm/Teak-Cleaner-1ltr-bring-back-original-colour-new-teak-hardwood-/220929631080
                      [itemCategoryId] =&gt; 4621162015
                      [itemCategoryUrl] =&gt; http://stores.ebay.co.uk/JATI-Teak-and-Woven-Furniture/_i.html?_fsub=4621162015
                  )
  
          )
  
      [8389242015] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [itemId] =&gt; 222388502715
                      [itemName] =&gt; New Folding Round Teak Picnic Table Wood Garden Premium 50cm Foldup Solid Sale
                      [itemPrice] =&gt; 33.33
                      [itemCurrencySign] =&gt; £
                      [itemGalleryUrl] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/bWcAAOSw4DJYiIOA/$_57.JPG?set_id=8800005007
                      [itemImages] =&gt; Array
                          (
                              [0] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/bWcAAOSw4DJYiIOA/$_57.JPG?set_id=8800005007
                              [1] =&gt; http://i.ebayimg.com/00/s/OTg1WDEwMDA=/z/kAoAAOSwo4pYiIOH/$_57.JPG?set_id=8800005007
                          )
  
                      [itemQuantity] =&gt; 50
                      [itemStartTime] =&gt; 2017-01-25T12:00:13.000Z
                      [itemEndTime] =&gt; 2017-02-24T12:00:13.000Z
                      [itemUrl] =&gt; http://www.ebay.com/itm/New-Folding-Round-Teak-Picnic-Table-Wood-Garden-Premium-50cm-Foldup-Solid-Sale-/222388502715
                      [itemCategoryId] =&gt; 8389242015
                      [itemCategoryUrl] =&gt; http://stores.ebay.co.uk/JATI-Teak-and-Woven-Furniture/_i.html?_fsub=8389242015
                  )
  
          )
  )    
  </code></pre>
  
  <p>and i want to get latest two items based on itemStartTime  across all items that are present inside multidimensional array so final array will look something like below</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [itemId] =&gt; 222388502715
              [itemName] =&gt; New Folding Round Teak Picnic Table Wood Garden Premium 50cm Foldup Solid Sale
              [itemPrice] =&gt; 33.33
              [itemCurrencySign] =&gt; £
              [itemGalleryUrl] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/bWcAAOSw4DJYiIOA/$_57.JPG?set_id=8800005007
              [itemImages] =&gt; Array
                  (
                      [0] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/bWcAAOSw4DJYiIOA/$_57.JPG?set_id=8800005007
                      [1] =&gt; http://i.ebayimg.com/00/s/OTg1WDEwMDA=/z/kAoAAOSwo4pYiIOH/$_57.JPG?set_id=8800005007
                  )
  
              [itemQuantity] =&gt; 50
              [itemStartTime] =&gt; 2017-01-25T12:00:13.000Z
              [itemEndTime] =&gt; 2017-02-24T12:00:13.000Z
              [itemUrl] =&gt; http://www.ebay.com/itm/New-Folding-Round-Teak-Picnic-Table-Wood-Garden-Premium-50cm-Foldup-Solid-Sale-/222388502715
              [itemCategoryId] =&gt; 8389242015
              [itemCategoryUrl] =&gt; http://stores.ebay.co.uk/JATI-Teak-and-Woven-Furniture/_i.html?_fsub=8389242015
          )
  
          [1] =&gt; Array
                  (
                      [itemId] =&gt; 220929631080
                      [itemName] =&gt; Teak Cleaner - 1ltr bring back the original colour of new teak/hardwood!
                      [itemPrice] =&gt; 19.5
                      [itemCurrencySign] =&gt; £
                      [itemGalleryUrl] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/HWIAAOSw8vZXMKGK/$_1.JPG?set_id=880000500F
                      [itemImages] =&gt; Array
                          (
                              [0] =&gt; http://i.ebayimg.com/00/s/NjU1WDgwMA==/z/HWIAAOSw8vZXMKGK/$_1.JPG?set_id=880000500F
                              [1] =&gt; http://i.ebayimg.com/00/s/MTEzMVgxNjAw/z/u8kAAOSw3mpXMKGT/$_1.JPG?set_id=880000500F
                          )
  
                      [itemQuantity] =&gt; 204
                      [itemStartTime] =&gt; 2012-01-10T16:59:50.000Z
                      [itemEndTime] =&gt; 2017-02-12T16:59:50.000Z
                      [itemUrl] =&gt; http://www.ebay.com/itm/Teak-Cleaner-1ltr-bring-back-original-colour-new-teak-hardwood-/220929631080
                      [itemCategoryId] =&gt; 4621162015
                      [itemCategoryUrl] =&gt; http://stores.ebay.co.uk/JATI-Teak-and-Woven-Furniture/_i.html?_fsub=4621162015
                  )
  
  
  
  )
  </code></pre>
  
  <p>TBH i am totally lost on this one not getting clue other then parsing sorting each out and using foreach but that would be way too slow for bigger arrays </p>
  
  <p>any help on this would be really awesome!</p>
  
  <p>My solution till now is this rearranging each array and preparing a new array that will just hold items and then sort them like this </p>
  
  <pre><code>foreach ($storeItemsArray as $key =&gt; $value)
                  foreach ($value as $key_sub =&gt; $value_sub)
                      $itemsArray[]=$value_sub;
  
  
  
              // sort items and get the latest first
              usort($itemsArray, function($a, $b) {
                        $ad = new DateTime($b['itemStartTime']);
                        $bd = new DateTime($a['itemStartTime']);
  
                        if ($ad == $bd) {
                          return 0;
                        }
  
                      return $ad &lt; $bd ? -1 : 1;
              });
  </code></pre>
  
  <p>Something better then just give me a heads up i am just concerned it would be slow for arrays holding 400 or 500 items :(</p>