PHP in_array() Function
Complete PHP Array Reference Manual
Example
Search an array for the value "Runoob" and output some text:
Run Example »
Definition and Usage
The in_array() function searches an array for a specified value.
Syntax
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
| Parameters | Description |
|---|---|
| needle | Required. Specifies the value to search for in the array. |
| haystack | Required. Specifies the array to search. |
| strict | Optional. If set to TRUE, the in_array() function also checks whether the type of the searched data matches the type of the array value. |
Technical Details
| Return Value: | Returns TRUE if the value is found in the array, FALSE otherwise. |
|---|---|
| PHP Version: | 4+ |
| Changelog | Since PHP 4.2, the search parameter can be an array. |
More examples
Example 1
Using all parameters:
" ; } else { echo " Match not found" ; } if ( in_array ( " Glenn " , $people , TRUE ) ) { echo " Match found
" ; } else { echo " Match not found
" ; } if ( in_array ( 23 , $people , TRUE ) ) { echo " Match found
" ; } else { echo " Match not found
" ; } ?>
Run Example »
Complete PHP Array Reference Manual