over 9 years ago
What is tht sort() function in php ?
The sort() function sorts an indexed array in ascending order means lowest to highest .
why use sort() function in php ?
Sort() function basically use for sort the elements of the array in ascending alphabetical order:
You can see below example of sort() function in php.
- <?php
- $Name=array("Sanny","Mac","Brandam");
- //here $Name is a variable
- sort($Name);
- //now call the sort() for sorting name in alphabetical order
- //loop start for count name
- for($i=0;$i<count($Name);$i++)
- {
- echo $Name[$i];
- echo "<br>";
- }
- ?>
<?php $Name=array("Sanny","Mac","Brandam"); //here $Name is a variable sort($Name); //now call the sort() for sorting name in alphabetical order //loop start for count name for($i=0;$i<count($Name);$i++) { echo $Name[$i]; echo "<br>"; } ?>
output will come following:
Brandam
Mac
Sanny
0 Comment(s)