Home > Article > Backend Development > PHP determines whether a value exists in an array
PHP in_array() function checks whether a value exists in the array and returns TRUE if it exists, otherwise it returns FALSE.
Syntax: (Recommended learning: PHP programming from entry to proficiency)
bool in_array( mixed needle, array array [, bool strict] )
Parameter description:
needle, the value that needs to be searched in the array, if it is a string, it is case sensitive
array, the array that needs to be retrieved
strict, optional, if set Is TRUE, the value type in needle and array will also be checked
Example:
<?php $arr_a = array("a", "b", "c", 1); if(in_array("a", $arr_a)){ echo '字符 a 在 $arr_a 数组中存在'; } else { echo '字符 a 在 $arr_a 数组中不存在'; } ?>
Character a exists in the $arr_a array Strict check Example:
<?php $arr_a = array("a", "b", "c", 1); if(in_array("1", $arr_a, TRUE)){ echo '字符 1 在 $arr_a 数组中存在'; } else { echo '字符 1 在 $arr_a 数组中不存在'; } ?>
The above is the detailed content of PHP determines whether a value exists in an array. For more information, please follow other related articles on the PHP Chinese website!