<?php
$a=['apples'=>10,'bananas'=>15,'carrots'=>100,'oranges'=>25,'tomatoes'=>5];
arsort($a);
var_dump($a);
uksort($a, function ($a, $b) {
if ($a == 'bananas' || $a == 'tomatoes') return 0;
return ($b == 'bananas' || $b == 'tomatoes') ? 1 : 0;
});
var_dump($a);
- Output for 7.0.0 - 7.0.20, 7.1.0 - 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
- array(5) {
["carrots"]=>
int(100)
["oranges"]=>
int(25)
["bananas"]=>
int(15)
["apples"]=>
int(10)
["tomatoes"]=>
int(5)
}
array(5) {
["bananas"]=>
int(15)
["tomatoes"]=>
int(5)
["carrots"]=>
int(100)
["oranges"]=>
int(25)
["apples"]=>
int(10)
}
preferences:
193.71 ms | 404 KiB | 213 Q