← All built-ins / ksort()

ksort()

ksort(array &$a): bool

Parameters

NameTypeDescription
$aarraymap to sort by key (by reference)

Return value

true; sorted ascending by key, key/value association kept.

Example

$m = ["b" => 2, "a" => 1];
ksort($m);
echo implode(",", array_keys($m));
a,b

See also

krsort()asort()uksort()