This article mainly introduces the implementation of PHP to the two-dimensional array of all the one-dimensional array to add values, involving PHP for the array of traversal, conversion, assignment and other related operations skills, the need for friends can refer to the following
Specific as follows:
Adds values (indexes and associations) to all one-dimensional arrays in a two-dimensional array
$shop = Array ( 0=>array (0=>1,1=>2,2=>3,3=>4) , 1=>array (0=>1,1=>2,2=>3) , 2 =>array (0=>1,1=>2,2=>3) );p Rint_r ($shop);///Example 1: Address assignment of a reference loop variable foreach ($shop as & $shoplist) { $shoplist [] = ' 4444444444444 '; $shoplist [' we '] = ' Welcome to the home of the script ';} Print_r ($shop);
Operation Result:
Array ([0] = = Array ([0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = = 4444444444444 [We] + Welcome to Script House) [1] = = Array ([0] = 1 [1] = 2 [2] = 3 [3] = 4444444444444 [We] = Welcome to Script house) [2] = = Array ([0] = = 1 [1] = 2 [2] = 3 [3] = + 4444444444444 [We] + Welcome to the home of the script)
Example 2: Modifying an array of loop variables, re-assigning a value of foreach ($shop as $key = = $shoplist) { $index = count ($shoplist); $shoplist [$index] = ' 4444444444444 '; $shoplist [' we '] = ' Welcome to the home of the script '; $shop [$key]= $shoplist;} Print_r ($shop);
Operation Result:
Array ([0] = = Array ([0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = = 4444444444444 [We] + Welcome to Script House) [1] = = Array ([0] = 1 [1] = 2 [2] = 3 [3] = 4444444444444 [We] = Welcome to Script house) [2] = = Array ([0] = = 1 [1] = 2 [2] = 3 [3] = + 4444444444444 [We] + Welcome to the home of the script)
The above is the whole content of this article, I hope that everyone's study has helped.