How to sort php array with custom keys?
$arr = array("41" => "10", "20" => "5");
I need to sort array by values with saving keys.
I tried sort()
but it changes keys to associative 0..n
How to sort php array with custom keys?
$arr = array("41" => "10", "20" => "5");
I need to sort array by values with saving keys.
I tried sort()
but it changes keys to associative 0..n
You can use asort()
for sorting array based on values:
asort($arr);