In PHP array function the in_array() function mainly used to check the item are available or not in array.
In_array() Syntax:
in_array( 'search_item' , $array, boolean)
Where,
boolean - It is used to check strict validation. And this field is optional one. If you want the strict validation you can use this.
We using in_array() function to performing following following two function. That is ,
1. Non-strict validation
2. Strict validation
1. Non-strict validation:
This method to validate array with some negotiation. And it allow two parameters.
For example,
$array_sample = array ( 'key1' => 567 , 'key2' => 579);
in_array('key1', $array_sample); // output1: true
in_array('577', $array_sample, false); // output2: true
Note: the Example 1, we use only two parameter. Because we can't mention `false` value. Because In default the in_array() take `false` as a boolean value.
In above example,
Example 1 : The `key1` is not value in the array. This is key of the array. So this scenario the in_array accept the search key as a value of the array.
Example 2: The value `577` is not in the value and key of the array. It is some similar to the value `579`. So this is also accepted.
So this reason this type is called non-strict function.
2. Strict validation
This method to validate array without any negotiation. And it have three parameters. If you only mention two parameter the `in_array()` function take as a non-strict validation.
For example,
$array_sample = array ( 'key1' => 567 , 'key2' => 579);
in_array('key1', $array_sample , true); // output1: false
in_array('577', $array_sample, true); // output2: false
This is return `true` only the search string is match exactly with the array value with case sensitivity.
Thanks for your time.