亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

數組推送到在php中給出空值的鍵

數組推送到在php中給出空值的鍵

PHP
呼喚遠方 2022-07-16 18:22:50
所以我從 json 中獲取一些輸入,即用戶 ID。然后我試圖找到它的朋友和他們的博客以及它各自的評論。顯然,評論將不止一個。因此,每當我將這些評論推送到數組中的一個鍵時,我都會在我的 api 響應中得到空值。我嘗試使用簡單的 $name['comments'] = $res. 但由于會有多個評論,因此它會用舊評論替換新評論。請幫我解決這些問題CoDE->   $userdata = json_decode(file_get_contents('php://input'));    $userid = mysqli_real_escape_string($conn, $userdata->userid);    // =============================================================================    // ===========================Get Friends=======================================    // =============================================================================    $friends = "    SELECT  `friend_one`                FROM    `friends`                WHERE   `friend_two` = '$userid' AND `status` = '1'                UNION ALL                SELECT  `friend_two`                FROM    `friends`                WHERE   `friend_one` = '$userid' AND `status` = '1'            ";    $response = array();    $friendsq = mysqli_query($conn, $friends);    if(!$friendsq) {        $response['statusCode'] = 400;        $response['message'] = "failed to connect to backend. please contact developer";    }    $count = mysqli_num_rows($friendsq);    // =============================================================================    // ===========================No Friends=======================================    // =============================================================================    if($count == 0) {        $response['statusCode'] = 202;        $response['message'] = "No Friends to show the newsfeed";    } else {        $response['statusCode'] = 200;        $response['message'] = "Success";        $response['microblogs'] = array();        $name['comments'] = array();        // =============================================================================
查看完整描述

1 回答

?
GCT1015

TA貢獻1827條經驗 獲得超4個贊

而不是array_push($name['comments'], $res);,使用$name['comments'][] = $res;. 這記錄array_push.



查看完整回答
反對 回復 2022-07-16
  • 1 回答
  • 0 關注
  • 162 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號