If the last argument is true, it will use strict (also known as identity) comparison (===
) when searching the array.
The equality comparison (==
) compares the value where as the identity comparison (===
) compares the value and the type.
'0' == 0 ; //true, the string is converted to an integer and then the are compared.
'0' === 0; //false, a string is not equal to a integer
You will find more information in this question How do the equality (== double equals) and identity (=== triple equals) comparison operators differ?
This means that if you had an array of numbers
$a = array(0,1,2,3,4);
Using a strict comparison for the string value '2'
will return false (not find a match) as there are no strings with the value '2'
.
array_search('2', $a, true); //returns false
However if you don't do a strict search, the string is implicitly converted into an integer (or the other way around) and it returns the index of 2
, as 2 == '2'
array_search('2', $a, false); //returns 2