Jul 112010
Sort an array by key in PHP
Answer:
Assume you have an array in PHP as following,
$a = array (
"orange" => 3,
"mango" => 2,
"apple" => 1,
);
You can sort the array by the key, with the ksort function
ksort($a);
Then the array become:
(
"apple" => 1,
"mango" => 2,
"orange" => 3,
);