array("Maths"=>"0","Francais"=>"0","Anglais"=>"0","Histoire">
当前位置:Gxlcms > PHP教程 > PHP二维数组追加赋值有关问题~

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

时间:2021-07-01 10:21:17 帮助过:15人阅读

PHP 二维数组追加赋值问题~~~~~~~~~
我有一个学生名字和成绩的数组

$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

人气教程排行