How do I sort an array by key?
This takes the name of the array as the parameter, and works like this:
<?php
$myworld = array("c"=>"better","a"=>"make","b"=>"me");
print_r($myworld);
?>
This prints:
Array
(
[c] => better
[a] => make
[b] => me
)
We need to use ksort to get the right key order:
<?php
$myworld = array("c"=>"better","a"=>"make","b"=>"me");
ksort($myworld);
print_r($myworld);
?>
Array
(
[a] => make
[b] => me
[c] => better
)
Comment on this Question and Answer >>>
ASK A QUESTION
More arrays PHP Questions
How do I find out if a value is already in an array?How do I remove an element from an array without changing the index values for the rest of the array?
How can I display values in a two dimensional array?
What is the starting salary of Php developer in india?? after 1 year experience how much i could get??
what is a array?
