Want to sort an array values alphabetically in PHP? Use the sort() function for sorting the numeric array elements or values alphabetically or numerically in the ascending order.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php $text = array("Sky", "Cloud", "Birds", "Rainbow", "Moon"); $numbers = array(1, 2, 3.5, 5, 8, 10); // Sorting the array of string sort($text); print_r($text); echo "<br>"; // Sorting the array of numbers sort($numbers); // Print the output print_r($numbers); ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.