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 return all the values in an array?how can you reset an array in PHP
How do I find out if a value is already in an array?
i need to store a multi-dimensioned array into a file. there is plenty of info. on creating md-arrays but i cant find anything on writing a md-array to a file.
How do I find if a value is already in an array or not?
