How to sort associative arrays by values in ascending order PHP

1 Answer

0 votes
$arr = array("php"=>"99", "c"=>"108", "c++"=>"31", "python"=>"21");

asort($arr);

foreach ($arr as $key => $value) {
  echo $key . " - " . $value . "\n";
}
 
 
 
/*
run:
 
python - 21
c++ - 31
php - 99
c - 108
 
*/

 



answered Mar 5, 2021 by avibootz

Related questions

2 answers 217 views
1 answer 188 views
1 answer 163 views
2 answers 217 views
1 answer 129 views
...