In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you how php judges whether array elements are numbers, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can get something after reading this article, let's take a look at it.
Judgment method: 1, use foreach loop through the array, syntax "foreach ($arr as $v) {}"; 2, in the loop body, use is_numeric () to determine whether the array element is a number, syntax "if (is_numeric ($v)) {echo" $v is a number ";}".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
How does php determine whether an array element is a number?
1. Use foreach to loop through the array
Foreach is a statement specially designed to traverse an array. It is a common method when traversing an array and provides great convenience in traversing an array. After PHP5, you can also traverse objects (foreach can only be applied to arrays and objects).
The foreach statement traverses an array independent of the array subscript and can be used for discontiguous indexed arrays and associative arrays with strings as subscript.
Syntax:
Foreach ($array as $value) {statement block;}
Iterate through the given $array array, assigning the value of the current array to $value in each loop.
2. In the body of the loop, use the is_numeric () function to determine whether the array element $value is a number.
The is_numeric () function is used to detect whether a variable is a number or a numeric string.
Returns TRUE if the specified variable is a number and a numeric string, otherwise returns FALSE. Note that floating-point returns 1, that is, TRUE.
Example:
That's all of the article "how php determines whether an array element is a number". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.