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

The name of the pictureThe name of the pictureThe name of the pictureClash 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.





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


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' );

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard