Home >Backend Development >PHP Problem >How to determine whether an array value exists in php
In PHP, you can use the in_array() function to determine whether the array value exists. The function of this function is to search whether the specified value exists in the array. The syntax is "in_array(search,array,type)"; Returns TRUE if the value exists, FALSE otherwise.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use in_array () function to determine whether the array value exists.
in_array() function can search whether the specified value exists in the array.
Syntax:
in_array(search,array,type)
search Required. Specifies the value to search for in the array.
array Required. Specifies the array to search.
#type Optional. If this parameter is set to true, it is checked whether the type of the searched data and the value of the array are the same.
Return value: TRUE if the value is found in the array, otherwise FALSE.
Note:
If the search parameter is a string and the type parameter is set to TRUE, the search is case-sensitive.
Returns true if the given value search exists in the array array. If the third parameter is set to true, the function returns true only if the element exists in the array and has the same data type as the given value.
If the parameter is not found in the array, the function returns false.
Example: Determine whether the array value "Glenn" exists
<?php header("Content-type:text/html;charset=utf-8"); $people = array("Bill", "Steve", "Mark", "David"); if (in_array("Mark", $people)) { echo "指定值存在"; } else { echo "指定值不存在"; } ?>
Recommended study:《PHP video tutorial》
The above is the detailed content of How to determine whether an array value exists in php. For more information, please follow other related articles on the PHP Chinese website!