我正在尝试在脚本中使用implode()将SQL查询的结果作为字符串返回,以便我可以将其插入到另一个表中,但是每当我设法让内爆返回任何内容时,它只会返回一个结果,即使查询返回多个结果。
注意:我的PHP不是最强的,我正在使用预先存在的代码并对其进行返工,这就是为什么很多代码看起来像是为JSON API准备的。
$rows = $stmt->fetchAll();
if ($rows) {
$response["success"] = 1;
$response["message"] = "Events Scheduled!";
$response["events"] = array();
foreach ($rows as $row) {
$post = array();
$post["id"] = $row["id"];
$post["message"] = $row["message"];
$post["pin"] = $row["pin"];
array_push($response["events"], $post);
$matstring=implode("', '",$post);
}
}
当回声传出时,我得到:
3', '测试以检查数组中的多个条目,以便在进行检查时,应该看到这一点。', '12345
内爆$response['events']返回"数组,数组",我尝试过的其他一切都不返回任何内容。我应该在哪里获得其他条目?
我想你想要的是这样的:
$str = "'".implode(",'", $post)."'";
echo $str;