PHP two-dimensional join array Traversal method (instance description), two-dimensional instance description

Source: Internet
Author: User

PHP two-dimensional join array Traversal method (instance description), two-dimensional instance description

The foreach loop is used to traverse the two-dimensional index array, which is relatively faster and more efficient. The foreach loop is used by PHP to loop the array.

The instance is relatively simple. You just need to practice more and find out the program running logic.

<? Php $ arr = array (// defines the outer array "Beijing director" => array (1, 'gao mou', 'a company', 'beijing', '(010) 987654321 ', 'GM @ Linux.com'), // sub-array 1 "Shanghai manager" => array (2, 'loom', 'B', 'shanghai ', '(021) 123456789', 'lm @ apache.com '), // sub-array 2 "Tianjin owner" => array (3, 'fengmou', 'c company ', 'tianjin City ',' (022) 24680246 ', 'fm @ mysql.com'), // sub-array 3 "Chongqing owner" => array (4, 'shu mou ', 'd company ', 'chongqing', '(023) 13579135', 'sm @ php.com ') // subarray 4 ); foreach ($ arr as $ key => $ arr_item) {echo $ key; // retrieves the array key echo "<pre>"; print_r ($ Rr_item); // $ arr_item is the sub-array echo "</pre>"; foreach ($ arr_item as $ value) {echo $ value. "==="; // array value }}?>

Summary:

1. When traversing two-dimensional joined arrays, The for loop may not be used.

2. $ key: extract the key of the $ arr array.

3. $ arr_item is a sub-array (sub-array 1, Sub-array 2 .....)

The above two-dimensional PHP Association array Traversal method (for example) is all the content shared by the editor. I hope to give you a reference, and hope you can provide more support for the customer's house.

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.