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 we sort an array of names taken from a text file, displaying only unique names?how can you reset an array in PHP
Hi. i have a music samples website. in one table, id like a different sample to appear every time the page is refreshed. how do i acheve this? how can i alterate and retrieve these bloody mp3's? surely i can use a PHP script? thankyou
when i fetch the record in the database but they skip first record in the database
sort
