programming faqs interview questions tech technical educational freshers guide preparation interviews hr telephonic
try another color:
try another fontsize: 60% 70% 80% 90%
ProgrammingFAQs

How to sort an array values in php

Average: 5 (2 votes)

using asort function we can

using asort function we can sort array values, it sorts the values only, it maintain the index association.

$countries = array(1=>'us', 2=>'ind', 3=>'canada')
asort($countries)
foreach($countries as $key=>$val) {
echo "$key = $val \n";
}

o/p will be

3 = canada
2 = ind
1 = us