Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,111 questions

40,781 answers

573 users

How to sort associative arrays by values in descending order PHP

2 Answers

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

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

 





answered Mar 5, 2021 by avibootz
edited Sep 23, 2023 by avibootz
0 votes
$array = array("php"=>3, "c"=>12, "c++"=>7, "python"=>18, "java"=>11);
 
arsort($array);
 
foreach ($array as $key => $value) {
    echo $key . " " . $value . "\n";
}
  
  
  
/*
run:
  
python 18
c 12
java 11
c++ 7
php 3
  
*/

 





answered Sep 23, 2023 by avibootz

Related questions

...