bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
- $needle : searched value , If needle is a string, the comparison is done in a case-sensitive manner.
- $haystack: the array
- $strict: If it is set to TRUE then the in_array() function will also check the types of the needle in the haystack.
For example
I have an array that is declared like the followings:const Mac = 0; $os = array("NT", "Irix", "Linux",Mac);Firstly, I try to check is there any 'Mac' value in array or not
if (in_array("Mac", $os)) { echo "Got Mac"; }you will see the result is :
Got MacLet's try it again with $strict parameter is set to TRUE
if(in_array("Mac", $os, true)){ echo "got 'Mac'"; } else echo "do not got any 'Mac'";This time it got the diffrent result
do not got any 'Mac'Because of the $strict parameter is set to TRUE, in_array function will also check the type of value when check in array. As you can see, the type of Mac is integer, while type of searched value is String.
The comparison is also done in case-sensitive manner. By searching 'mac' value in array, you can see that by the following commands:
if (in_array("mac", $os)) { echo "Got mac"; } else echo "do not got any 'mac'";and the result is:
do not got any 'mac'