在我的脚本中,我查询MySQL数据库并将结果添加到数组中。
$result = mysqli_query($ssdbc,$q);
$rows = array();
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$rows[] = $row;
}
这是输出:
Array
(
[systName] => ahu17s
[x] => 499
[y] => 133
)
Array
(
[systName] => 11zktl
[x] => 667
[y] => 280
)
Array
(
[systName] => zy12px
[x] => 485
[y] => 111
)
那么,如何为每个数组添加一个额外的键,这样在编辑之后,每个数组项都会如下所示:
Array
(
[systName] => ahu17s
[x] => 499
[y] => 133
[NEW_KEY] => SOME_VALUE
)
谢谢!
答案 0 :(得分:2)
$result = mysqli_query($ssdbc,$q);
$rows = array();
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$row["foo"] = "bar";
$rows[] = $row;
}
也许是这样的?未经测试。
答案 1 :(得分:0)
$result = mysqli_query($ssdbc,$q);
$rows = array();
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$row['NEW_KEY'] = 'SOME_VALUE';
$rows[] = $row;
}