- krsort: documentation ( source)
- asort: documentation ( source)
- arsort: documentation ( source)
- ksort: documentation ( source)
<?php
$age=array("Sophia"=>"31","Jacob"=>"41","William"=>"39","Ramesh"=>"40");
echo "Sorting the associative array in ascending order by value <br> ";
asort($age);
foreach($age as $key=>$value)
{
echo "key is : ".$key." , value is : ".$value." ";
}
echo "Sorting the associative array in ascending order by key <br> ";
ksort($age);
foreach($age as $key=>$value)
{
echo "key is : ".$key." , value is : ".$value." ";
}
echo "Sorting the associative array in descending order by value <br> ";
arsort($age);
foreach($age as $key=>$value)
{
echo "key is : ".$key." , value is : ".$value." ";
}
echo "Sorting the associative array in descending order by key <br> ";
krsort($age);
foreach($age as $key=>$value)
{
echo "key is : ".$key." , value is : ".$value." ";
}
?>