This article mainly introduces the method of sorting arrays by using the sort () function in php. The example analyzes the functions and related usage skills of the sort () function in php, which is very useful, for more information about how php sorts arrays by using the sort () function, see the following example. Share it with you for your reference. The specific analysis is as follows:
The sort () function is used to sort arrays. this function assigns a new key name to the elements in the array. The original key name is deleted.
If the call succeeds, TRUE is returned. otherwise, FALSE is returned.
$ Alpha = array ("x", "a", "f", "c"); sort ($ alpha); foreach ($ alpha as $ var) {print "$ var
";}
Example 2
<? Php $ my_array = array ("a" => "Dog", "B" => "Cat", "c" => "Horse"); sort ($ my_array ); print_r ($ my_array);?>
Returned results
Array ([0] => Cat [1] => Dog [2] => Horse)
I hope this article will help you with php programming.