PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How can I sort an array keeping the correlation between the index and value?


If you want to do this, then it's time to think of 'a' for 'associative', and use this sort function rather than the regular sort function.

Otherwise it functions the same: asort($array);

<?php
$myworld 
= array("a"=>"php","b"=>"learning","c"=>"i'm");
asort($myworld);
print_r($myworld);
?>


Which prints:

Array
(
[c] => i'm
[b] => learning
[a] => php
)



More arrays PHP Questions

How do I check if a variable is of array type?
How do I reverse sort an array by key?
How do I turn an array into a string?
How do I add to the beginning of an array and find the number of elements in it?
How do I reverse sort the members of an array?