本文实例讲述了PHP实现给二维数组中所有一维数组添加值的方法。分享给大家供大家参考,具体如下:
给二维数组中所有的一维数组添加值(索引和关联)
array(0=>1,1=>2,2=>3,3=>4),1=>array(0=>1,2=>3),2=>array(0=>1,2=>3)
);
print_r($shop);
//示例 1:引用循环变量的地址赋值
foreach($shop as &$shoplist){
$shoplist[] = '4444444444444';
$shoplist['we'] = '欢迎光临编程之家';
}
print_r($shop);
运行结果:
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 4444444444444 [we] => 欢迎光临编程之家 )
[1] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4444444444444 [we] => 欢迎光临编程之家 )
[2] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4444444444444 [we] => 欢迎光临编程之家 )
)
$shoplist){
$index = count($shoplist);
$shoplist[$index] = '4444444444444';
$shoplist['we'] = '欢迎光临编程之家';
$shop[$key]=$shoplist;
}
print_r($shop);
运行结果:
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 4444444444444 [we] => 欢迎光临编程之家 )
[1] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4444444444444 [we] => 欢迎光临编程之家 )
[2] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4444444444444 [we] => 欢迎光临编程之家 )
)
更多关于PHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家PHP程序设计有所帮助。
原文链接:https://www.f2er.com/php/18040.html