php - Make in_array not convert between numeric and alpha values -


i want make in_array return true in these cases:

in_array(0, [0]); in_array(0, ['0']); in_array('0', [0]); in_array('0', ['0']); 

but @ same time, return false in cases such this:

in_array(0, ['a']); in_array('0', ['a']); in_array('a', ['0']); in_array('a', [0]); in_array(1, [true]); 

what's simplest solution this?

almost of examples working, except

in_array(0, ['a']); 

however, can convert integer value string that:

in_array(strval(0), ['a']); 

this work if there numbers in array:

in_array('0', [0]); // returns true 

or:

$needle = 'a'; $array = [0]; in_array(strval($needle), array_map(function($value) { return strval($value); }, $array)); 

or:

$needle = 'a'; $array = [0]; $mapped_array = array_map(     function($value) {         if (is_numeric($value))             return strval($value);         else             return $value;     },     $array ); in_array(strval($needle), $mapped_array, true); 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -