Home  >  Article  >  Backend Development  >  How to sort an array in php through the sort() function, sort array_PHP tutorial

How to sort an array in php through the sort() function, sort array_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:02:53969browse

How PHP sorts an array through the sort() function, sort array

The example in this article describes how PHP sorts an array through the sort() function. Share it with everyone for your reference. The specific analysis is as follows:

The sort() function is used to sort the array. This function assigns new key names to the cells in the array. The original key name will be deleted.
Returns TRUE if successful, FALSE otherwise.

$alpha = array ("x", "a", "f", "c");
sort( $alpha );
 
foreach ( $alpha as $var ) {
 print "$var<br />";
}

Example 2

<&#63;php
$my_array = array("a" => "Dog", "b" => "Cat", "c" => "Horse");
sort($my_array);
print_r($my_array);
&#63;>

Return results

Array
(
[0] => Cat
[1] => Dog
[2] => Horse
)

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969489.htmlTechArticlephp uses the sort() function to sort the array. The sort array example in this article describes how php uses the sort() function. Method to sort an array. Share it with everyone for your reference. The specific analysis is as follows:...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn