Learning PHP
Advanced PHP
PHP Function Reference
PHP Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
PHP Function in_array()
Syntax
in_array ( $value, $array [,$strict ] );
|
Definition and Usage
The in_array() function searches an array for a specific value. If the third parameter strict is set to TRUE then the in_array() function will also check the types of the $value.
Paramters
Parameter | Description |
value | Required. Value to be search in array. |
array | Required. Specifies an array |
strict | Optional. If this parameter is set, the in_array() function searches for the search-string and specific type in the array. |
Return Value
This function returns TRUE if the value is found in the array, or FALSE otherwise.
Example
Try out following example:
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
|
This will produce following result:
|
|
|