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 ))