<?php $arr = array ( "100" => array( array( "country" => 'France', "city" => 'Paris', "population" => '1800000', ), array( "country" => 'France', "city" => 'Paris', "population" => '2000000', ), array( "country" => 'France', "city" => 'Toulouse', "population" => '500000', ), ), "101" => array( array( "country" => 'Russia', "city" => 'Moscow', "population" => '144000000', ) ) ); foreach($arr as $k => &$ar) { $mins = array_reduce($ar, function ($carry, $item) { $key = $item["country"] . "###" . $item["city"]; $carry[$key] = (isset($carry[$key]) && $item["population"] > $carry[$key]) ? $carry[$key] : $item["population"]; return $carry; }, []); $ar = array_filter($ar, function ($item) use ($mins) { $key = $item["country"] . "###" . $item["city"]; return $mins[$key] == $item["population"]; }); } print_r($arr);
You have javascript disabled. You will not be able to edit any code.