Home > Article > Backend Development > PHP uses in_array function to check whether a value exists in an array_PHP tutorial
This article mainly introduces PHP using the in_array function to check whether a certain value exists in the array, with a more detailed analysis The function, definition and related usage skills and precautions of the in_array function are explained. It has certain reference value. Friends in need can refer to it
The example in this article describes how PHP uses the in_array function to check whether a certain value exists in an array. Share it with everyone for your reference. The specific analysis is as follows:
PHP uses the in_array() function to check whether a certain value exists in the array. If it exists, it returns TRUE, otherwise it returns FALSE. It is very easy to use. Let me introduce the in_array() function to you in depth.
When I was writing a piece of code in PHP recently, I needed to determine whether a certain value was in another set of values. The in_array function is used to check whether a certain value exists in the array. It is relatively vague to understand directly through concepts, and its function can be understood through specific examples.
The syntax is as follows:
?
|
bool in_array( mixed needle, array array [, bool strict] )
|
参数 | 说明 |
---|---|
needle | 需要在数组中搜索的值,如果是字符串,则区分大小写 |
array | 需要检索的数组 |
strict | 可选,如果设置为 TRUE ,则还会对 needle 与 array 中的值类型进行检查 |
Parameter description:
Example 1:
1 2 3 4 5 6 7 8 9 |
$os = array("Mac", "NT", "Irix", "Linux"); if (in_array("Irix", $os)) { echo "Got Irix"; } if (in_array("mac", $os)) { echo "Got mac"; } ?> |
1 2 3 4
5 6
9 |
$os = array("Mac", "NT", "Irix", "Linux"); if (in_array("Irix", $os)) {
The output result is: 1.13 found with strict check Example 4: Applying arrays within arrays
?
Statement: The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn Previous article:PHP implements RSA encryption class example_PHP tutorialNext article:PHP implements RSA encryption class example_PHP tutorial Related articlesSee more |