Array Functions

PHP supports arrays that are indexed both by integers and by arbitrary strings—known as associative arrays. Internally, PHP does not distinguish between associative arrays and integer-indexed arrays, as arrays are implemented as hash tables. Here are the array functions supported by PHP:

array array(...)

Create an array that contains all of the specified arguments

int array_walk(array array_arg, string function)

Apply a function to every member of an array

int arsort(array array_arg)

Sort an array in reverse order and maintain index association

int asort(array array_arg)

Sort an array and maintain index association

int count(mixed var)

Count the number of elements in a variable (usually an array)

mixed current(array array_arg)

Return the element currently pointed to by the internal array pointer

mixed each(array array_arg)

Return the next key/value pair from an array

mixed end(array array_arg)

Advance the array’s internal pointer to the last element and return the value of that element

mixed key(array array_arg)

Return the key of the element currently pointed to by the internal array pointer

int ksort(array array_arg)

Sort an array by key

mixed max(mixed arg1 [, mixed arg2 [, ...]])

Return the highest value in an array or a series of arguments

mixed min(mixed arg1 [, mixed arg2 [, ...]])

Return the lowest value in an array or a series of arguments

mixed next(array array_arg)

Move the array’s internal pointer to the next element and return the value of that element ...

Get Webmaster in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.