欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實現(xiàn)給二維數(shù)組中所有一維數(shù)組添加值的方法

 更新時間:2017年02月04日 14:14:00   作者:風(fēng)起從容  
這篇文章主要介紹了php實現(xiàn)給二維數(shù)組中所有一維數(shù)組添加值的方法,涉及php針對數(shù)組的遍歷、轉(zhuǎn)換、賦值等相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了php實現(xiàn)給二維數(shù)組中所有一維數(shù)組添加值的方法。分享給大家供大家參考,具體如下:

給二維數(shù)組中所有的一維數(shù)組添加值(索引和關(guān)聯(lián))

$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)
  );
print_r($shop);
//示例 1:引用循環(huán)變量的地址賦值
foreach($shop as &$shoplist){
  $shoplist[] = '4444444444444';
  $shoplist['we'] = '歡迎光臨腳本之家';
}
print_r($shop);

運行結(jié)果:

Array (
[0] => 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] => 歡迎光臨腳本之家 )
)

//示例2:修改循環(huán)變量數(shù)組,重新賦值
foreach($shop as $key=>$shoplist){
  $index = count($shoplist);
  $shoplist[$index] = '4444444444444';
  $shoplist['we'] = '歡迎光臨腳本之家';
  $shop[$key]=$shoplist;
}
print_r($shop);

運行結(jié)果:

Array (
[0] => 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] => 歡迎光臨腳本之家 )
)

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計算法總結(jié)》、《php排序算法總結(jié)》、《PHP常用遍歷算法與技巧總結(jié)》、《PHP數(shù)學(xué)運算技巧總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論