Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


getResponse autofunnels

Liquid Web Cloud VPS Hosting

Disclosure We are a professional Information website that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

12,094 questions

16,479 answers

573 users

How to use sort functions to sort an array in PHP

8 Answers

0 votes
$arr = array("ccc", "aaaaaaaaaaaaaaa", "ddddddd", "b");

sort($arr);

print_r($arr);

 
/*
run:
 
Array ( [0] => aaaaaaaaaaaaaaa [1] => b [2] => ccc [3] => ddddddd ) 
 
*/

 




answered Nov 17, 2015 by avibootz
edited Nov 17, 2015 by avibootz
0 votes
$arr = array(7, 3, 1, 2, 4);

sort($arr);

print_r($arr);

 
/*
run:
 
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 7 ) 
 
*/

 




answered Nov 17, 2015 by avibootz
0 votes
$arr = array(7, 3, 1, 2, 4);

rsort($arr);

print_r($arr);

 
/*
run:
 
Array ( [0] => 7 [1] => 4 [2] => 3 [3] => 2 [4] => 1 ) 
 
*/

 




answered Nov 17, 2015 by avibootz
0 votes
$arr = array("ccc", "aaaaaaaaaaaaaaa", "ddddddd", "b");

rsort($arr);

print_r($arr);

 
/*
run:
 
Array ( [0] => ddddddd [1] => ccc [2] => b [3] => aaaaaaaaaaaaaaa ) 
 
*/

 




answered Nov 17, 2015 by avibootz
0 votes
$arr = array("C"=>"95", "C++"=>"85", "PHP"=>"75");

asort($arr); // Ascending Order by Value

print_r($arr);

 
/*
run:
 
Array ( [PHP] => 75 [C++] => 85 [C] => 95 ) 
 
*/

 




answered Nov 17, 2015 by avibootz
0 votes
$arr = array("C"=>"95", "C++"=>"85", "PHP"=>"75");

ksort($arr); // Ascending Order by Key 

print_r($arr);

 
/*
run:
 
Array ( [C] => 95 [C++] => 85 [PHP] => 75 ) 
 
*/

 




answered Nov 17, 2015 by avibootz
0 votes
$arr = array("C"=>"95", "C++"=>"85", "PHP"=>"75");

arsort($arr); // Descending Order by Value 

print_r($arr);

 
/*
run:
 
Array ( [C] => 95 [C++] => 85 [PHP] => 75 )
 
*/

 




answered Nov 17, 2015 by avibootz
0 votes
$arr = array("C"=>"95", "C++"=>"85", "PHP"=>"75");

krsort($arr); // Descending Order by Key 

print_r($arr);

 
/*
run:
 
Array ( [PHP] => 75 [C++] => 85 [C] => 95 ) 
 
*/

 




answered Nov 17, 2015 by avibootz
...