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

WBOY
Release: 2016-07-13 10:02:53
Original
993 people have browsed it

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 />";
}
Copy after login

Example 2

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

Return results

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

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:...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template