search
Homephp教程php手册php数组函数序列之ksort()对数组的元素键名进行升序排序,保持索引关系

php数组函数序列之ksort()对数组的元素键名进行升序排序,保持索引关系

Jun 13, 2016 pm 12:04 PM
ksortphpelementrelationfunctionAscending orderrightsequencesortarrayofindexconductKey name

ksort()定义和用法
ksort() 函数按照键名对数组升序排序,为数组值保留原来的键。

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

若成功,则返回 TRUE,否则返回 FALSE。

语法
ksort(array,sorttype)参数 描述
array 必需。规定要排序的数组。
sorttype 可选。规定如何排列数组的值。可能的值:

SORT_REGULAR - 默认。以它们原来的类型进行处理(不改变类型)。
SORT_NUMERIC - 把值作为数字来处理
SORT_STRING - 把值作为字符串来处理
SORT_LOCALE_STRING - 把值作为字符串来处理,基于本地设置*。


*:该值是 PHP 4.4.0 和 5.0.2 新加的。在 PHP 6 之前,使用了系统的区域设置,可以用 setlocale() 来改变。自 PHP 6 起,必须用 i18n_loc_set_default() 函数。

例子

复制代码 代码如下:


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


输出:

Array( [b] => Cat [c] => Horse [e] => Sog)
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor