php ksort() function


  Translation results:

英[sɔ:t]   美[sɔ:rt]   

n.Classification, category; quality, nature; method; a group

vt.& vi.Classification; rectification, arrangement ;Suitable for

vt.Select;Category;Arrange…vi.Classification;Communication;Coordination

php ksort() functionsyntax

Function: Sort the associative array in ascending order according to the key name

Syntax: ksort(array,sortingtype)

Parameters:

ParametersDescription
array Required . Specifies the array to be sorted.
sortingtype Optional. Specifies how the elements/items of an array are arranged. Possible values: 0 = SORT_REGULAR - Default. Put each item in regular order (Standard ASCII, don't change the type). 1 = SORT_NUMERIC - treat each item as a number. 2 = SORT_STRING - Treat each item as a string. 3 = SORT_LOCALE_STRING - Treat each item as a string, based on the current locale (can be changed with setlocale()). 4 = SORT_NATURAL - Treat each item as a string, using natural sorting like natsort(). 5 = SORT_FLAG_CASE - Strings can be sorted in combination (bitwise OR) with SORT_STRING or SORT_NATURAL, case-insensitively.

Description: Sort the array according to the key name and retain the original key for the array value. The optional second parameter contains additional sorting flags. Returns TRUE if successful, FALSE otherwise.

php ksort() functionexample

<?php
$age=array("西门"=>"60","无忌"=>"31","灭绝"=>"56");
ksort($age);
print_r($age);
?>

Run Instance»

Click the "Run Instance" button to view the online instance

Output:

Array ( [无忌] => 31 [灭绝] => 56 [西门] => 60 )

Home

Videos

Q&A