Welcome to the Linux Community Forum and interact with 2 million technicians>> Enter PHP is a scripting language for WEB development. I think everyone has a deep understanding of it. Here I will talk about PHP Let’s discuss array traversal with you. I hope it will be helpful to you. Detailed explanation on the installation of Apache 2.0 and PHP5.0. Expert guide to PHP installation and configuration. Mainstream Apache 2 PHP
Welcome to the Linux Community Forum and interact with 2 million technical staff>>Enter
PHP is a scripting language for WEB development. I think everyone has a deep understanding of it. Here I Let’s discuss with you about PHP array traversal. I hope it will be helpful to you.
Detailed explanation on the installation of Apache 2.0 and PHP5.0
Expert guide to PHP installation and configuration
Introduction to the installation and use of mainstream Apache 2 PHP5
In-depth study of PHP configuration
Detailed introduction to PHP array loop operations
We all realize the superiority of arrays, and now we will learn how to traverse data in PHP arrays. The application of this method of operating arrays is very common, and I believe you will master it well. For example, your website stores a large amount of URL data. You want to display the portal URL on a page. These data have been saved in an array variable $url. So how do you output these data to the web page one by one? Do you still imagine echo outputting one by one like the previous lesson? Don’t forget that the amount of data is very large and the number of data changes frequently.
PHP array traversal syntax:
foreach (array_expressionas$key=>$value) statement
The second format does the same thing, except for the key value of the current cell It will also be assigned to the variable $key in each loop.
For example 1:
Note: When foreach starts executing, the pointer inside the array will automatically point to the first unit. This means there is no need to call reset() before the foreach loop. Note: Also note that foreach operates on a copy of the specified array, not the array itself. Therefore, even if there is an each() construct, the original array pointer does not change, and the value of the array unit is not affected. Note: foreach does not support the ability to use “@” to suppress error messages.