我正在尝试从数据库动态地将新数组添加到现有数组中,但我的循环仅添加 mysql_fetch_row 中的最后一行。我认为它实际上是在覆盖同一个数组。
PHP 代码
<?php
$con = require_once('./dbconnect.php');
global $con;
mysql_select_db("packages", $con);
$packages = mysql_query("SHOW TABLES FROM packages");
while($row = mysql_fetch_row($packages)){
$node = array();
foreach($row as $key2 => $value2){
$node[$row[0]] = array("Item1" => "Other dynamic Info here");
}
}
print_r($node);
mysql_close($con);
?>
输出如下:
Array
(
[Pack1] => Array
(
[Item1] => Other dynamic Info here
)
)
它应该输出:
Array
(
[Pack1] => Array
(
[Item1] => Other dynamic Info here
)
)
Array
(
[Pack2] => Array
(
[Item2] => Other dynamic Info here
)
)
我一直试图让这个 foreach() 循环工作大约一天......我做错了什么?