(PHP 5 >= 5.2.0, PHP 7)

ArrayObject::ksortSort the entries by key


public ArrayObject::ksort ( void ) : void

Sorts the entries by key, maintaining key to entry correlations. This is useful mainly for associative arrays.


This function has no parameters.

Return Values

No value is returned.


Example #1 ArrayObject::ksort() example

= array("d" => "lemon""a" => "orange""b" => "banana""c" => "apple");
$fruitArrayObject = new ArrayObject($fruits);

foreach (
$fruitArrayObject as $key => $val) {
"$key = $val\n";

The above example will output:

a = orange
b = banana
c = apple
d = lemon

See Also

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top