In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this article, the editor introduces in detail "how to use php's foreach grammar". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use php's foreach grammar" can help you solve your doubts.
There is a foreach syntax in php, and the php foreach syntax structure provides a simple way to traverse an array, such as "foreach (iterable_expression as $value) statement".
This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.
Does php have foreach syntax?
Php has foreach syntax.
The foreach syntax structure provides an easy way to traverse an array. Foreach can only be applied to arrays and objects, and an error message will be sent if you try to apply to variables of other data types, or uninitialized variables.
There are two grammars:
Foreach (iterable_expression as $value) statementforeach (iterable_expression as $key = > $value) statement
The first format traverses the given iterable_expression iterator. In each loop, the value of the current unit is assigned to $value.
The second format does the same thing, except that the key name of the current unit is assigned to the variable $key in each loop.
Note that foreach does not modify the array internal pointers used by functions like current () and key ().
You can also customize traversal objects.
You can easily modify the elements of an array by adding & before $value. This method assigns a value by reference rather than copying a value.
Note:
The $value reference to the last element of the array remains after the foreach loop. It is recommended that you use unset () to destroy it. Otherwise, you will encounter the following situation:
You can traverse the value of an array constant by reference:
Note:
Foreach does not support the ability to suppress error messages with "@".
Example:
Read here, this article "how to use php foreach grammar" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more about the article, 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.