-1
$array_list = ['125268', '526985', '8566958'];

in_array('125268', $array_list); //Returning True

in_array('0125268', $array_list); // Also Returning True

I want second one should return false as it have zero at the beginning. But in_array() is ignoring the zero.

Any Suggestions?

JMP
  • 4,417
  • 17
  • 30
  • 41

1 Answers1

1

You have to set the third parameter. This is an optional parameter and is of boolean type. This parameter specifies the mode in which we want to perform the search. If it is set to TRUE, then the in_array() function searches for the value with the same type of value as specified by the first parameter. The default value of this parameter is FALSE.

$array_list = ['125268', '526985', '8566958'];

in_array('125268', $array_list, true); // Returning True

in_array('0125268', $array_list, true); // Returning False

Visit here for more information.

Biswajit Biswas
  • 859
  • 9
  • 20
  • 1
    When you see a simple question asked in 2021, you can be sure it is already asked and answered many times on Stack Overflow. Please close duplicate questions instead of answering them. – mickmackusa Dec 15 '21 at 11:11