我的问题是,我从 SQL 查询中填充了数组,并希望将数组合并到一个新数组中,其中查询的 id 不是重复的,我尝试了 merge_array 并且当我通过 URL 执行函数时它没有显示数组中的内容我刚刚得到 ARRAY。还尝试将数组连接到另一个数组并获得相同的结果,我的问题再次是如何加入数组并正确显示它。
$rows[0] = array("181", "a","g"); //Results from previous query
$rows[1] = array("181","j","L")
$rows[2] = array("181","p");
$rows[3] = array("182","k");
$rows[4] = array("183","l");
$rows[5] = array("183","p");
$id =0;
$commentsH = "";
while( $row=mysql_fetch_array($query_comments) ){
If($id == $image){ //image id is the first element in array.
$comments[] =$row;
$commentsH = $comments.",".$commentsH[$i];
}
else{
$id = $image;
$i = $i +1;
}
}
$result = array();
$result["result"] = 500;
$result["message"] = "Database Read Successfully";
$result["comments"] =$commentsH;
echo json_encode($result);
exit;
EXPECTED OUTPUT
$commentsH[0] = array("181", "a","g","j","L","p");
$commentsH[1] = array("182","k");
$commentsH[2] = array("183","l","p");