PHP array traversal syntax

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff. PHP is a scripting language for WEB development. I think you have a deep understanding of it, here I will discuss PHP array traversal and hope to help you. Apache2.0 and PHP5.0 installation expert guide PHP installation and configuration mainstream Apache2PHP

Welcome to the Linux community forum and interact with 2 million technical staff> entering PHP is a scripting language for WEB development. I think you have a deep understanding of it, here I will discuss PHP array traversal and hope to help you. How to install and configure Apache 2.0 and PHP5.0

Welcome to the Linux community forum and interact with 2 million technicians>

PHP is a scripting language for WEB development. I think you have a deep understanding of it. Here I will discuss PHP array traversal and hope to help you.

How to install Apache 2.0 and PHP5.0

PHP installation and configuration

Introduction to mainstream Apache 2 PHP5 Installation and Use

Deep Learning about PHP configuration

PHP array loop operations

We all know the superiority of arrays. Now we will learn how to traverse the data in PHP arrays. The application of this array method is very common, and I believe you will have a good grasp. For example, if your website contains a large amount of website data and you want to display the portal website on a page, the data has been saved to an array variable $ url, so how to output the data one by one to a webpage? Do you still think of echo output one by one in the previous lesson? Don't forget that the data size is very large and the number of data changes frequently.

PHP array traversal Syntax:

Foreach (array_expressionas $ key => $ value) statement

In the second format, only the key value of the current unit is assigned to the variable $ key in each loop.

Example 1:


Note: When foreach starts to execute, the pointer inside the array automatically points to the first unit. This means that you do not need to call reset () before the foreach loop (). Note: foreach operates on a copy of the specified array, rather than the array itself. Therefore, even if each () is constructed, the original array pointer is not changed, and the value of the array unit is not affected. Note: foreach does not support "@" to prohibit error messages.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.