3v4l.org

run code in 300+ PHP versions simultaneously
<?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', "population" => '144000000', ) ) ); foreach($arr as $key => $sub){ foreach($sub as $item){ if(isset($item['city'])){ if(!isset($res[$key][$item['country'] . $item['city']])) $res[$key][$item['country'] . $item['city']] = $item; if($res[$key][$item['country'] . $item['city']] < $item['population']) $res[$key][$item['country'] . $item['city']] = $item; }else{ if(!isset($res[$key][$item['country']])) $res[$key][$item['country']] = $item; if($res[$key][$item['country']] < $item['population']) $res[$key][$item['country']] = $item; } } } var_dump($res);
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { [100]=> array(2) { ["FranceParis"]=> array(3) { ["country"]=> string(6) "France" ["city"]=> string(5) "Paris" ["population"]=> string(7) "1800000" } ["FranceToulouse"]=> array(3) { ["country"]=> string(6) "France" ["city"]=> string(8) "Toulouse" ["population"]=> string(6) "500000" } } [101]=> array(1) { ["Russia"]=> array(2) { ["country"]=> string(6) "Russia" ["population"]=> string(9) "144000000" } } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.04 ms | 407 KiB | 5 Q