<?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 ) { //это просто что бы не копипастить завернул.
$temp = function ( $city ) {
return " " . $city [ "name" ] . "(" . $city [ "population" ] . ")" ;
} ;
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+ICLQmNC90LTQvtC90LXQt9C40Y8iLCAicG9wdWxhdGlvbiIgPT4gIjMw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