我在更新多维关联数组的值时遇到问题。该数组$people
是从另一个 MySQL 调用生成的。With :
array_push($people, array("forename" => $pat_f_name, "surname" => $pat_s_name,"id" => $id));
我设置了$forname
and $surname
to ""
,只是为了把钥匙放在那里。
我正在尝试遍历进行 SQL 调用的数组并检索相关的名字和姓氏,然后更新该数组索引处的键。
以下是我迄今为止的尝试。
提前致谢。
$stmt = $mysql->stmt_init();
foreach ($people as $person)
{
if($stmt->prepare("SELECT forename,surname FROM worker WHERE id = ?"))
{
$stmt->bind_param('i', $p_id);
$p_id = $person["id"];
$stmt->execute();
$stmt->bind_result($f_name, $s_name);
while($stmt->fetch())
{
$people[$person]["forename"] = $f_name;
$people[$person]["surname"] = $s_name;
}
}
}
$stmt->close();