Learn php sorting function_PHP tutorial

WBOY
Release: 2016-07-13 10:36:33
Original
754 people have browsed it

Note: This function assigns a new key name to the unit in the array. The original key name will be deleted.

Returns TRUE if successful, otherwise returns FALSE.

$my_array = array("a" => "Dog", "b" => "Cat", "c" => "Horse");

sort($my_array);
print_r($my_array);
?>
output:
Array
(
[0] => Cat
[1] => Dog
[2] => Horse
)
asort() function sorts the array and maintains the index relationship. Mainly used for sorting associative arrays where the order of cells is important.

The optional second parameter contains additional sorting flags.

Returns TRUE if successful, otherwise returns FALSE.

$my_array = array("a" => "Dog", "b" => "Cat", "c" => "Horse");

asort($my_array);
print_r($my_array);
?>
output:

Array
(
[b] => Cat
[a] => Dog
[c] => Horse
)

The ksort() function sorts the array by key name, retaining the original keys for the array values.

The optional second parameter contains additional sorting flags. www.jbxue.com

Returns TRUE if successful, otherwise returns FALSE.

$my_array = array("a" => "Dog", "b" => "Cat", "c" => "Horse");
ksort ($my_array);
print_r($my_array);
?>
output:

Array
(
[a] => Dog
[b] => Cat
[c] => Horse
)
The difference between the above three functions is The key name, key value, and whether to change the index vary

>>> Articles you may be interested in:







www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/738552.htmlTechArticleNote: This function assigns a new key name to the unit in the array. The original key name will be deleted. Returns TRUE if successful, FALSE otherwise. ?php $my_array = array("a" = "Dog", "b...
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