In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of php how to query the existence of a value in the array, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this php how to query the existence of a certain value in the array. Let's take a look.
Query the existence of the method: 1, use in_array () function, syntax "in_array (value, $array)"; 2, use array_search () function, syntax "array_search (value, $array)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php queries whether a value value exists in the array
Method 1: use the in_array () function
The in_array () function looks up whether a value is included in the array, returns TRUE if it exists, or FALSE if it doesn't exist. The syntax format is as follows:
In_array ($needle, $array [, $strict = FALSE])
The parameters are described as follows:
$needle: the value to be searched. If $needle is a string, it is case-sensitive when comparing.
$array: the array to be searched
$strict: optional parameter. Default is FALSE.
If $strict is empty or FALSE, the in_array () function simply checks whether the value of $needle is equal to the value in $array
If the value of $strict is TRUE,in_array (), the function not only checks the values in $needle and $array, but also compares whether their types are equal.
Example:
Method 2: use the array_search () function
The array_search () function searches the array for a key value, and returns the corresponding key name if the specified key value is found in the array, otherwise it returns FALSE. The syntax format is as follows:
Array_search (value,array,strict)
Value is required. Specifies the key value to search in the array.
Array is required. Specifies the array to be searched.
Strict is optional. If this parameter is set to TRUE, the function searches the array for elements with the same data type and value. Possible values:
If set to true, the type of the given value is checked in the array, and the number 5 is different from the string 5 (see example 2).
True
False-default
If the key value is found more than once in the array, the key name that matches the first found key value is returned.
Example:
This is the end of the article on "how php queries whether a value exists in an array". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how php queries whether a certain value exists in the array". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.