Search the array for the value "codercto" and output some text:
<?php $sites = array ( " Google " , " codercto " , " Taobao " , " Facebook " ) ; if ( in_array ( " codercto " , $sites ) ) { echo " Match found! " ; } else { echo " No match found! " ; } ?> Run instance»The in_array() function searches an array for the presence of a specified value.
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
parameter | describe |
---|---|
needle | Required. Specifies the value to search for in the array. |
haystack | Required. Specifies the array to search. |
strict | Optional. If this parameter is set to TRUE, the in_array() function checks whether the data being searched is of the same type as the value of the array. |
Return value: | Returns TRUE if the value is found in the array, otherwise returns FALSE. |
---|---|
PHP version: | 4+ |
Change log | Since PHP 4.2, the search parameter can be an array. |
Use all parameters:
<?php $people = array ( " Peter " , " Joe " , " Glenn " , " Cleveland " , 23 ) ; if ( in_array ( " 23 " , $people , TRUE ) ) { echo " Match found<br> " ; } else { echo " Match not found<br> " ; } if ( in_array ( " Glenn " , $people , TRUE ) ) { echo " Match found<br> " ; } else { echo " Match not found<br> " ; } if ( in_array ( 23 , $people , TRUE ) ) { echo " Match found<br> " ; } else { echo " Match not found<br> " ; } ?>