我一直在尝试以 json 形式返回 2 个查询的结果。var_dump($data)有效,但不能json_encode返回空/不工作。
$data = array();
$array_articles = array();
$sql_articles = $mysqli->query("select something something");
while ( $article = $sql_articles->fetch_assoc() ){
$array_articles[] = $article;
}
$array_posts = array();
$sql_posts = $mysqli->query("select something something");
while ( $post = $sql_posts->fetch_assoc() ){
$array_posts[] = $post;
}
$data = array(
'top_articles' => $array_articles,
'top_posts' => $array_posts
);
echo json_encode( $data );
慕的地8271018