<?php
$cities = [
[ "name" => "Джакарта" , "country" => "Индонезия" , "population" => "30539000" ] ,
[ "name" => "Токио" , "country" => "Япония" , "population" => "37843000" ] ,
[ "name" => "Шанхай" , "country" => "КНР" , "population" => "23416000" ] ,
[ "name" => "Нью-йорк" , "country" => "США" , "population" => "20630000" ] ,
[ "name" => "Москва" , "country" => "Россия" , "population" => "16170000" ] ,
[ "name" => "Дели" , "country" => "Индия" , "population" => "24998000" ] ,
[ "name" => "Мехико" , "country" => "Мексика" , "population" => "20063000" ] ,
[ "name" => "Стамбул" , "country" => "Индия" , "population" => "13287000" ] ,
[ "name" => "Карачи" , "country" => "Пакистан" , "population" => "22123000" ] ,
[ "name" => "Лондон" , "country" => "Великобритания" , "population" => "10236000" ] ,
] ;
function filterByPopulation( $cities ) { //эту функцию было легко написать
return ( $array [ "population" ] > 20000000 ) ;
} ) ;
}
function printCities( $cities ) { //это просто что бы не копипастить завернул.
echo " " , $city [ "name" ] . "(" . $city [ "population" ] . ")" ;
} , $cities ) ;
echo "\n \n " ;
}
$firstTask = filterByPopulation( $cities ) ;
echo "Города с населением больше 20млн:" ;
printCities( $firstTask ) ;
function sortByPopulation( $cities ) { //вот тут у меня был затуп
$condition = function ( $a , $b ) { //пришлось воровать пример с мануала и "переделывать".
if ( $a [ "population" ] == $b [ "population" ] ) {
return 0 ;
}
return ( $a [ "population" ] > $b [ "population" ] ) ? - 1 : 1 ;
} ;
usort ( $cities , $condition ) ; }
$secondTask = sortByPopulation( $cities ) ;
echo "Список 3х самых населенных городов по убыванию:" ;
printCities( $secondTask ) ;
$result = array_column( $test , 'country' ) ;
echo "Они находятся в странах: " . implode ( ", " , $result ) . "." ;
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKJGNpdGllcyA9IFsKCQlbIm5hbWUiID0+ICLQlNC20LDQutCw0YDRgtCwIiwgImNvdW50cnkiID0+ICLQmNC90LTQvtC90LXQt9C40Y8iLCAicG9wdWxhdGlvbiIgPT4gIjMwNTM5MD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