3v4l.org

run code in 300+ PHP versions simultaneously
<?php $amsterdam = [ 65 => [ 'table' => 'Object', 'something' => false, 'data' => [ 'foo' => 'boo', 'price' => 100 ] ], 173 => [ 'table' => 'Object', 'something' => false, 'data' => [ 'foo' => 'hoo', 'price' => 2500 ] ], ]; $prague = [ 132 => [ 'table' => 'Object', 'something' => false, 'data' => [ 'foo' => 'boo', 'price' => 2100 ] ], 956 => [ 'table' => 'Object', 'something' => false, 'data' => [ 'foo' => 'hoo', 'price' => 2500 ] ], ]; $lisboa = [ 175 => [ 'table' => 'Object', 'something' => false, 'data' => [ 'foo' => 'boo', 'price' => 6500 ] ], 64 => [ 'table' => 'Object', 'something' => false, 'data' => [ 'foo' => 'hoo', 'price' => 20 ] ], ]; $cities = [ 'amsterdam' => $amsterdam, 'prague' => $prague, 'lisboa' => $lisboa ]; $map_prices = function($n) { $reduce_smallest_price = function($carry, $item) { return $item['data']['price'] < $carry ? $item['data']['price'] : $carry; }; return array_reduce($n, $reduce_smallest_price, INF); }; $cities_price = array_map($map_prices, $cities); asort($cities_price); uksort($cities, function($a, $b) { global $cities_price; return strnatcmp($cities_price[$a], $cities_price[$b]); }); print_r($cities_price); print_r($cities);
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Array ( [lisboa] => 20 [amsterdam] => 100 [prague] => 2100 ) Array ( [lisboa] => Array ( [175] => Array ( [table] => Object [something] => [data] => Array ( [foo] => boo [price] => 6500 ) ) [64] => Array ( [table] => Object [something] => [data] => Array ( [foo] => hoo [price] => 20 ) ) ) [amsterdam] => Array ( [65] => Array ( [table] => Object [something] => [data] => Array ( [foo] => boo [price] => 100 ) ) [173] => Array ( [table] => Object [something] => [data] => Array ( [foo] => hoo [price] => 2500 ) ) ) [prague] => Array ( [132] => Array ( [table] => Object [something] => [data] => Array ( [foo] => boo [price] => 2100 ) ) [956] => Array ( [table] => Object [something] => [data] => Array ( [foo] => hoo [price] => 2500 ) ) ) )

preferences:
135.46 ms | 418 KiB | 5 Q