in_array

bool in_array(mixed target, array array, [bool compare_types]) 
target Value for which to search
array Array in which to search for target
compare_types Whether to compare types or just values

Searches an array for an occurrence of a given value.

Returns:

TRUE if the target value exists within the given array; FALSE otherwise

Description:

This function searches through array for an element with the value given by target . If compare_types is given and is TRUE, elements match only if they have the same value and type as target ; otherwise, only the values need to match.

Version:

PHP 4

Example:

Check for the existence of a value within an array
 $array = array(1, 2, '3', 4); if (in_array(3, $array)) { echo "Found.\n"; } else { echo ...

Get PHP Functions Essential Reference 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.