php in_array() checks whether a certain value exists in the array
in_array checks whether a certain value exists in the array
Basic grammar:
bool in_array(mixed $needle,array $haystack,bool $strict=FALSE)
Search needle in haystack
Parameter introduction
Parameters | Description |
---|---|
needle | Required. Specifies the value to search for in the array. If it is a string, the comparison is case-sensitive. |
haystack | Required. Specifies the array to search. |
strict | Optional. If this parameter is set to true, the in_array() function also checks whether the type of needle is the same as that in haystack. |
Return value
Returns TRUE if needle is found, otherwise returns FALSE.
Example:
<?php $os = array( "Mac", "NT", "Irix", "Linux" ); if (in_array("Irix", $os)) { echo "Got Irix"; } if (in_array("mac", $os)) { echo "Got mac"; } ?>
Running the second condition online fails because in_array() is case-sensitive, so the above program displays:
Got Irix
Thanks for reading, I hope it can help everyone, thank you for your support of this site!