1 回答
TA贡献1891条经验 获得超3个赞
(复制自评论)
$comments在顶部之外创建一个数组foreach并推入该数组而不是$coo["comments"]. 然后,echo json_encode($comments)在外面做之后foreach。
global $id_comentador;
global $id_comentario;
global $comment;
$arregloComentarios = json_decode($row['comentarios'], true);
$comments = [];
foreach ($arregloComentarios as $value) {
$id_comentario = $value["id_comentario"];
$id_comentador = $value["id"];
$comment = $value["comment"];
$consultarComentador = "select id,first_name,last_name,foto from users where id='$id_comentador';";
$arregloProyectos = traerDatos($consultarComentador);
$num = count($arregloProyectos);
if ($num > 0) {
foreach ($arregloProyectos as $row2) {
$foto = $row2["foto"];
$foto2 = $row2["first_name"];
$foto3 = $row2["last_name"];
$tmp = array();
$tmp["id_comment"] = $id_comentario;
$tmp["photo"] = $foto;
$tmp["full_name"] = $foto2.''.$foto3;
$tmp["comment"] = $comment;
$comments[] = $tmp;
}//Cierra foreach
}
}
echo json_encode($comments);
- 1 回答
- 0 关注
- 81 浏览
添加回答
举报