Array sort in php

We can sort array in php by using built-in sort function, Now we define an array with some elements.
<?php
$arr=array("Kimmi","Alen","Mike","Bob");
?>
Now for sorting array we call php function sort and pass our array as its argument.
<?php
sort($arr);
foreach($arr as $val)
{
	print $val."<br/>";
}
?>
The result we get is as:
Alen
Bob
Kimmi
Mike
For reverse sorting php built-in function is rsort(). Agian taking above example.
<?php
$arr=array("Kimmi","Alen","Mike","Bob");
rsort($arr);
foreach($arr as $val)
{
	print $val."<br/>";
}
?>


The result we get is as:
Mike
Kimmi
Bob
Alen

For sorting associative array asort built-in function is used.

<?php
 $arr=array("first_name"=>"Peter","last_name"=>"Jackson","age"=>"25"); 
 asort($arr);
 foreach($array as $key=>$val)
 {
  print $val."<br/>"; 
 }
 ?>
The result is
25
Jackson
Peter

For key wise sorting of associative array, ksort built-in function is used. Here keys are changed

<?php
 $arr=array("x"=>"Peter","a"=>"Jackson","c"=>"25"); 
 ksort($arr);
 foreach($array as $key=>$val)
 {
  print $val."<br/>"; 
 }
 ?>
The result is
Jackson
25
Peter

For key wise reverse sorting of associative array, krsort built-in function is used.

<?php
 $arr=array("x"=>"Peter","a"=>"Jackson","c"=>"25"); 
 krsort($arr);
 foreach($array as $key=>$val)
 {
  print $val."<br/>"; 
 }
 ?>
The result is
Peter
25
Jackson