Home > php教程 > php手册 > php排序函数学习

php排序函数学习

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 09:41:23
Original
943 people have browsed it

注释:本函数为数组中的单元赋予新的键名。原有的键名将被删除。

如果成功则返回 TRUE,否则返回 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() 函数对数组进行排序并保持索引关系。主要用于对那些单元顺序很重要的结合数组进行排序。

可选的第二个参数包含了附加的排序标识。

如果成功则返回 TRUE,否则返回 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
)

ksort() 函数按照键名对数组排序,为数组值保留原来的键。

可选的第二个参数包含附加的排序标志。www.jbxue.com

若成功,则返回 TRUE,否则返回 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
)
上面三函数区别在按键名、键值、是否改变索引而不同

>>> 您可能感兴趣的文章:







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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template