In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to judge whether php is an associative array". In daily operation, I believe many people have doubts about how to judge whether php is an associative array. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt that "php how to judge whether it is an associative array". Next, please follow the editor to study!
Method: 1, use "array_keys ($arr)" to get the array key name, return an array of key names; 2, traverse the key name array to determine whether the array element is a string, syntax "foreach ($k as $v) {if (is_string ($v)) {echo" is an associative array ";}}".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
What is an associative array
The subscript (key name) of an associative array consists of a mixture of numeric values and strings, and if an array has a key name that is not a number, then the array is an associative array.
How does php determine whether it is an associative array?
1. Use array_keys () to get the key name of the array
The array_key () function can get some or all the key names in the array and return an array of key names.
2. Use foreach to traverse the array of key names
In the body of the loop, determine whether any array element is a string
As long as one is a string, the array is an associative array
Foreach ($keys as $v) {if (is_string ($v)) {echo "is an associative array"; break;}}
An improvement: determine whether the array is an associative array or an indexed array
$keys=array_keys ($arr); $b = ""; foreach ($keys as $v) {if (! is_string ($v)) {$bounded false;} else {$bounded truth; break;}} if ($b) {echo "is an associative array";} else {echo "is not an associative array, but an indexed array";}
If the following array is detected:
$arr=array (1, 2, 3, 4, 5)
The output is:
At this point, the study on "how to determine whether php is an associative 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.