PHP's in_array bevahior surprises me -


this question has answer here:

while validating dynamic saving method in controller wanted make sure given case accepts 0 , 1 valid values. when tried manipulate input form, submitting 'aaa' value following still returns true. why that?

var_dump(in_array('aaa', [0, 1])); // true, expecting return false 

you need use "strict" setting, force function check types of elements well:

var_dump(in_array('aaa', [0, 1], true)); 

http://php.net/manual/en/function.in-array.php states

if third parameter strict set true in_array() function check types of needle in haystack.

the reason returns true because string truthy, , 1.

if( "aaa" ){ echo "you see me"; } 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -