in_array returns True from a value that not exists [duplicate]

Clash Royale CLAN TAG#URR8PPP
in_array returns True from a value that not exists [duplicate]
This question already has an answer here:
$arr = [ 'foo'=>true, 'bar' ];
var_dump( in_array('some',$arr) );
Why var_dump returns true if some does not exists in $arr?
var_dump
true
some
$arr
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
true
'some' == true
2 Answers
2
in_array() check for the values of the arrays.
in_array()
If you are setting a value as true, it will return true because of that, unless, as mentioned by @AymDev before, you set the third parameter to be strict.
true
true
just like this In your case
$arr = array('foo'=> 'true', 'bar' );
or
$arr = array('foo'=> 1, 'bar' );
Read the documentation. If you want a strict comparison you should set the 3rd parameter to
true, else'some' == true.– AymDev
Aug 3 at 9:57