Php implements the method of adding values to all one-dimensional arrays in a two-dimensional array. the dimension of the Two-dimensional array

Source: Internet
Author: User

Php implements the method of adding values to all one-dimensional arrays in a two-dimensional array. the dimension of the Two-dimensional array

This example describes how php adds values to all one-dimensional arrays in a two-dimensional array. We will share this with you for your reference. The details are as follows:

Add values (indexes and associations) to all one-dimensional arrays in a two-dimensional array)

$ Shop = array (0 => array (0 => 1, 1 => 2, 2 => 3 => 4 ), 1 => array (0 => 1, 1 => 2, 2 => 3), 2 => array (0 => 1, 1 => 2, 2 => 3 )); print_r ($ shop); // Example 1: quote the address of the Circular Variable with a value of foreach ($ shop as & $ shoplist) {$ shoplist [] = '2016 '; $ shoplist ['we'] = 'Welcome to ';} print_r ($ shop );

Running result:

Array ([0] => Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 4444444444444 [we] => welcome to the customer's house) [1] => Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4444444444444 [we] => welcome to the house of friends) [2] => Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4444444444444 [we] => welcome to the house of friends ))
// Example 2: Modify the array of loop variables and assign a new value to foreach ($ shop as $ key => $ shoplist) {$ index = count ($ shoplist ); $ shoplist [$ index] = '000000'; $ shoplist ['we'] = 'Welcome to '; $ shop [$ key] = $ shoplist ;} print_r ($ shop );

Running result:

Array ([0] => Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 4444444444444 [we] => welcome to the customer's house) [1] => Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4444444444444 [we] => welcome to the house of friends) [2] => Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4444444444444 [we] => welcome to the house of friends ))

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.