This is weird thing I found with
$test = array(
1 => 'first',
2 => 'second'
$val = 0;
$key = array_search($val, $test);
This is not a bug, but how PHP handles comparisons. As
$val is an integer, PHP will convert your strings to integers for the comparison. Converting
'first' to an integer will give you
0, and so the comparison is
0 == 0, which is obviously true. That's why it returns the first result.