PHP ksort() FunctionLast Updated : 17 Mar 2025 The PHP ksort() sorts an associative array in ascending order, according to the key. It is mainly used for an associative array. This function was introduced in PHP 4.0. SyntaxParameter
ReturnsThe ksort() function returns true on success and false on failure. Example 1Output:
Array
(
[ganguly] => 46
[sachin] => 45
[virat] => 29
)
Example 2Output:
Array
(
[a] => cricket
[b] => hockey
[c] => football
[d] => badminton
)
Example 3Output:
Array
(
[china] =>beijing
[france] =>paris
[india] =>newdelhi
[russia] =>moscow
[united kingdom] =>london
)
Example 4Output:
Array
(
[z] => ruby
[y] => java
[x] => html
)
Next TopicPhp-array-list-function |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India