-1
$arr = [ 'foo'=>true, 'bar' ];

var_dump( in_array('some',$arr) );

Why var_dump returns true if some does not exists in $arr?

nacesprin
  • 392
  • 7
  • 16
  • 3
    Read the [documentation](http://php.net/manual/en/function.in-array.php). If you want a strict comparison you should set the 3rd parameter to `true`, else `'some' == true`. – AymDev Aug 03 '18 at 09:57

2 Answers2

1

in_array() check for the values of the arrays.

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.

Rafael
  • 1,495
  • 1
  • 14
  • 25
0

just like this In your case

$arr =  array('foo'=> 'true', 'bar'  );
or 
$arr =  array('foo'=> 1, 'bar'  );
manish
  • 423
  • 3
  • 9