首頁  >  文章  >  後端開發  >  PHP 二维数组追加赋值问题~

PHP 二维数组追加赋值问题~

WBOY
WBOY原創
2016-06-23 14:04:201660瀏覽

我有一个学生名字和成绩的数组

$etudiants=array("AAA"=>array("Maths"=>"0","Francais"=>"0","Anglais"=>"0","Histoire-Geographie"=>"0","Sport"=>"0")	);


现在我想在后面追加一个赋值
"BBB"=>array("Maths"=>"1","Francais"=>"0","Anglais"=>"0","Histoire-Geographie"=>"0","Sport"=>"0")


变成
$etudiants=array("AAA"=>array("Maths"=>"0","Francais"=>"0","Anglais"=>"0","Histoire-Geographie"=>"0","Sport"=>"0"),"BBB"=>array("Maths"=>"1","Francais"=>"0","Anglais"=>"0","Histoire-Geographie"=>"0","Sport"=>"0")	);


谢谢


回复讨论(解决方案)

$etudiants["BBB"] = array("Maths"=>"1","Francais"=>"0","Anglais"=>"0","Histoire-Geographie"=>"0","Sport"=>"0");

$etudiants = array("AAA"=>array("Maths"=>"0","Francais"=>"0","Anglais"=>"0","Histoire-Geographie"=>"0","Sport"=>"0"));$additional = array("BBB"=>array("Maths"=>"1","Francais"=>"0","Anglais"=>"0","Histoire-Geographie"=>"0","Sport"=>"0"));$cards = array_merge($etudiants, $additional);  print "
";print_r($cards); 

更多参考
array_push/array_combine

哈哈谢谢了,
array_push/array_combine 这两个我试过了,效果不一样。

谢谢你的函数~~~~~~~~~~~~~~~

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn