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 do I sort the members of an array by value?


If you wish to sort the members of an array by value - which is probably one of the most common requirements with arrays as we tend to like to order things, use the sort function.

This takes the array as its parameter, as in sort($array).

Here's a simple example:

<?php
$myworld 
= array("world","hello");
sort($myworld);
print_r($myworld);
?>


Which looks a little like this:

Array
(
[0] => hello
[1] => world
)



More arrays PHP Questions

How do I remove and view the last element of an array?
How do I count the number of times a value appears in an array?
How do I find out if a value is already in an array?
How do I return all the values in an array?
How do I add to the end of an array and know how large the array is?