1 回答

TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊
(復(fù)制自評(píng)論)
$comments在頂部之外創(chuàng)建一個(gè)數(shù)組foreach并推入該數(shù)組而不是$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 關(guān)注
- 95 瀏覽
添加回答
舉報(bào)