sort an associative array by key after changing value in php code example
Example: php sort array by value and keep key
$weight = [
'Pete' => 75,
'Benjamin' => 309,
'Jonathan' => 101
];
asort($weight);
/*
weight is now:
Array
(
[Pete] => 75
[Jonathan] => 101
[Benjamin] => 309
)
To sort descending instead use: arsort
*/