We have an associative array where its values are all Boolean and if we search for a string, we got true.
Lets see an example.
<?php
$array = array(
'count' => 1,
'references' => 0,
'ghosts' => 1
);
var_dump(in_array('aurelio', $array));
And what we get is
true
Once again the in_array() function returns true. How is this possible?
The in_array has certain parameters such as:
0
false
0
NULL
array()
To solve this problem you can use in_array's third parameter. So, if we write:
<?php
$array = array(
'count' => 1,
'references' => 0,
'ghosts' => 1
);
var_dump(in_array('aurelio', $array, true));
well finally get
1 Comment(s)