In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "php how to judge whether a specified string belongs to an array". In daily operation, I believe many people have doubts about how php judges whether a specified string belongs to an array. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubt that "php how to judge whether a specified string belongs to an array". Next, please follow the editor to study!
Two methods: 1. Use is_array (), syntax "in_array (" value ", $arr,TRUE)", and return TRUE if it belongs to. 2. Use array_search (), syntax "array_search (" value ", $arr,true)", and return the corresponding key name if it belongs to.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
How does php determine whether a specified string belongs to an array?
Php determines whether the specified string belongs to an array, that is, whether the specified string is in the array. Now I would like to introduce several methods of judgment.
Method 1. Use the is_array () function to judge
The in_array () function searches for the existence of the specified value in the array.
You just need to set the first argument of the is_array () function to the specified string.
Returns TRUE if a value is found in the array, FALSE otherwise.
Example: determine whether the string "4" is in an array
You can see that there is a value of 4 in the array, but it is a numeric value, not a string, so the string "4" is not in the array.
Description:
The is_array () function has an optional third argument, which, if set to TRUE, checks whether the searched data is of the same type as the value of the array.
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, the corresponding key name is returned, otherwise FALSE is returned. 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: determine whether the string "1" is in an array
You can see that there is a value of 1 in the array, but it is a numeric value, not a string, so the string "1" is not in the array.
Description:
The array_search () function also has an optional third argument. If this parameter is set to TRUE, the function searches the array for elements with the same data type and value.
At this point, the study on "how php determines whether a specified string belongs to an array" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.