PHP array function sequence ksort() sorts the element key names of the array in ascending order and maintains the index relationship_PHP tutorial

WBOY
Release: 2016-07-21 15:23:40
Original
1050 people have browsed it

ksort() definition and usage
ksort() function sorts the array in ascending order by key name, retaining the original keys for the array values.

The optional second parameter contains additional sorting flags.

Returns TRUE if successful, otherwise returns FALSE.

Syntax
ksort(array,sorttype) Parameter Description
array Required. Specifies the array to be sorted.
sorttype optional. Specifies how to arrange the values ​​of an array. Possible values:

SORT_REGULAR - Default. Processed with their original type (without changing type).
SORT_NUMERIC - Handle values ​​as numbers
SORT_STRING - Handle values ​​as strings
SORT_LOCALE_STRING - Handle values ​​as strings, based on local settings*.


*: This value is newly added in PHP 4.4.0 and 5.0.2. Prior to PHP 6, the system locale was used, which could be changed with setlocale(). Since PHP 6, the i18n_loc_set_default() function must be used.

Example

Copy code The code is as follows:

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

Output:

Array( [b] => Cat [c] => Horse [e] => Sog)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324460.htmlTechArticleksort() definition and usage ksort() function sorts the array in ascending order according to the key name, retaining the original value of the array value key. The optional second parameter contains additional sorting flags. If successful, return...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!