Home Tutorial Php Phparray php array sort

 
 

php array sort
Posted on: October 27, 2009 at 12:00 AM
This section demonstrates the use of sort function in the php array.

  • PHP Array sort function is used to sort the given array in ascending order.


Example of PHP Array Sort

<?php

$ar1=array("jack","mac","rock","barak");

sort($ar1);

foreach ($ar1 as $a)

echo " ".$a;

echo "<br>";

$ar1=array("a"=>"jack","m"=>"mac","r"=>"rock","b"=>"barak");

sort($ar1);

foreach ($ar1 as $a=>$b)

echo " ".$a." ".$b;

?>

Output

barak jack mac rock
0 barak 1 jack 2 mac 3 rock 

Related Tags for php array sort:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.