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.
Parameters
| Sr.No | Parameter & Description |
|---|---|
| 1 |
value(Required) The value to be search in array. |
| 2 |
array(Required) It specifies an array |
| 3 |
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
$mobile_os = array("Mac", "android", "java", "Linux");
if (in_array("java", $mobile_os)) {
echo "Got java";
}
if (in_array("mac", $mobile_os)) {
echo "Got mac";
}
?>
This will produce the following result −
Got java
php_function_reference.htm
Advertisements