I am looking for code which Sort an Array in PHP. PHP Arrays can be two, tree or more dimensional but how to sort the array values and from which function?
I am looking for code which Sort an Array in PHP. PHP Arrays can be two, tree or more dimensional but how to sort the array values and from which function?
Php array sort example :
The output of this PHP code is:Code:<?php $narray[0]="Al"; $narray[1]="Ro"; $narray[2]="De"; $narray[3]="Te"; $narray[4]="Jo"; $narray[5]="Ch"; sort($narray); for($j=0; $j<6; $j++) { print $narray[$j] . "<br />"; } ?>
Al
Ch
De
Jo
Ro
Te
While Sorting an Array in PHP you need to use two functions: sort(), to sort an array in ascending order (From A to Z), and rsort(), to sort an array in the reverse order, or descending order (From Z to A).
PHP sort() Function : This function assigns new keys for the elements in the array. Existing keys will be removed.This function allows sorting of an array of objects too <?php. . This is a simplest array sort function in PHP. This function make a simple sort of the array values.
Bookmarks