I l@ve RuBoard Previous Section Next Section

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 "Not found.\n"; 
} 
if (in_array(3, $array, TRUE)) {
echo "Found.\n"; 
} else {
echo "Not found.\n"; 
} 

Output: 
Found. 
Not found. 
    I l@ve RuBoard Previous Section Next Section