In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 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 one-dimensional array or a two-dimensional array". In daily operation, I believe many people have doubts about how to judge an one-dimensional array or a two-dimensional array in php. The editor consulted all kinds of data and sorted out a simple and easy-to-use method of operation. I hope it will be helpful for you to answer the doubt that "php how to judge whether it is an one-dimensional array or a two-dimensional array". Next, please follow the editor to study!
In php, you can use the count () function to determine, this function can get the array length, if the second parameter is omitted, only one-dimensional number of elements will be obtained; so you only need to compare whether the length obtained is the same when omitting parameters and omitting parameters, syntax "count ($arr) = = count ($arr,1)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, the count () function can be used to determine.
The principle of the scheme:
Count (mixed $var [, int $mode])-calculates the number of elements in an array or the number of attributes in an object
$mode: optional parameter, which can be omitted.
If you omit the $mode parameter, or set it to COUNT_NORMAL or the 0account count () function will not detect multidimensional arrays
If $mode is set to COUNT_RECURSIVE or the 1 count () function will recursively count the number of elements in the array, it is especially useful for counting the number of elements in a multi-dimensional array.
If the $mode parameter is omitted, count does not detect multidimensional arrays and will only get the number of elements in one dimension.
So you only need to compare whether the length of the omitted $mode parameter is the same as that of the omitted $mode parameter to determine whether it is an one-dimensional array or a two-dimensional array.
Example of $mode parameters:
Output:
Array length: 6 non-recursive detection array, length: 3
Looking at the output above, I wonder if there are only five elements in the array ("Zhang San", 25, "High Mathematics", "PHP tutorial", "English"), and why the length of the array is not 5, but 6.
In fact, at this time, the count () function loops statistics of all the elements in the two-dimensional array, "array (" High number "," PHP tutorial "," English ")" will be counted as a whole once, and its elements ("High number", "PHP tutorial", "English") will be counted again, so the final result is 6.
At this point, the study on "how to judge whether php is an one-dimensional array or a two-dimensional 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.