You are here: Home // Array Functions

usort

(PHP3 >= 3.0.3, PHP4 ) usort –  Sort an array by values using a user-defined comparison function Description void usort (array array, string cmp_function) This function will sort an array by its values using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function. The

uksort

(PHP3 >= 3.0.4, PHP4 ) uksort –  Sort an array by keys using a user-defined comparison function Description void uksort (array array, function cmp_function) This function will sort the keys of an array using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function. Example

uasort

(PHP3 >= 3.0.4, PHP4 ) uasort –  Sort an array with a user-defined comparison function and maintain index association Description void uasort (array array, function cmp_function) This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where

sort

(PHP3 , PHP4 ) sort – Sort an array Description void sort (array array [, int sort_flags]) This function sorts an array. Elements will be arranged from lowest to highest when this function has completed. Example 1. Sort() example $fruits = array ("lemon", "orange", "banana", "apple"); sort ($fruits); reset ($fruits); while (list ($key, $val) = each ($fruits)) { echo "$key

sizeof

(PHP3 , PHP4 ) sizeof – Get the number of elements in an array Description int sizeof (array array) Returns the number of elements in the array. See also count().

shuffle

(PHP3 >= 3.0.8, PHP4 >= 4.0b4) shuffle – Shuffle an array Description void shuffle (array array) This function shuffles (randomizes the order of the elements in) an array. Example 1. Shuffle() example $numbers = range (1,20); srand (time()); shuffle ($numbers); while (list (, $number) = each ($numbers)) { echo "$number "; } See also arsort(), asort(),

rsort

(PHP3 , PHP4 ) rsort – Sort an array in reverse order Description void rsort (array array [, int sort_flags]) This function sorts an array in reverse order (highest to lowest). Example 1. Rsort() example $fruits = array ("lemon", "orange", "banana", "apple"); rsort ($fruits); reset ($fruits); while (list ($key, $val) = each ($fruits)) { echo "$key -> $val\n"; } This

reset

(PHP3 , PHP4 ) reset –  Set the internal pointer of an array to its first element Description mixed reset (array array) Reset() rewinds array’s internal pointer to the first element. Reset() returns the value of the first array element. See also: current(), each(), next(), and prev().

range

(PHP3 >= 3.0.8, PHP4 >= 4.0b4) range –  Create an array containing a range of integers Description array range (int low, int high) Range() returns an array of integers from low to high, inclusive. See shuffle() for an example of its use.

prev

(PHP3 , PHP4 ) prev – Rewind the internal array pointer Description mixed prev (array array) Returns the array element in the previous place that’s pointed by the internal array pointer, or false if there are no more elements. Warning If the array contains empty elements then this function will return false for these elements as well. To properly traverse
Copyright © 2010 PHP Manual. SiteMap.
Designed by Web Design SiteConstruct. Powered by WordPress.