The example in this paper describes how PHP implements the addition of values to all the one-dimensional arrays in a two-dimensional array. Share to everyone for your reference, 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 topic.alibabacloud.com ';} Print_r ($shop);
Operation Result:
Array ([0] = = Array ([0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = = 4444444444444 [We] + = Welcome to Topic.alib abacloud.com) [1] = = Array ([0] = 1 [1] = 2 [2] = 3 [3] + 4444444444444 [We] = Welcome to Topic.alibabacl oud.com) [2] = = Array ([0] = 1 [1] = 2 [2] = 3 [3] + 4444444444444 [We] = Welcome to TOPIC.ALIBABACLOUD.C OM))
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 topic.alibabacloud.com '; $shop [$key]= $shoplist;} Print_r ($shop);
Operation Result:
Array ([0] = = Array ([0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = = 4444444444444 [We] + = Welcome to Topic.alib abacloud.com) [1] = = Array ([0] = 1 [1] = 2 [2] = 3 [3] + 4444444444444 [We] = Welcome to Topic.alibabacl oud.com) [2] = = Array ([0] = 1 [1] = 2 [2] = 3 [3] + 4444444444444 [We] = Welcome to TOPIC.ALIBABACLOUD.C OM))
I hope this article is helpful to you in PHP programming.