所以我從 json 中獲取一些輸入,即用戶 ID。然后我試圖找到它的朋友和他們的博客以及它各自的評(píng)論。顯然,評(píng)論將不止一個(gè)。因此,每當(dāng)我將這些評(píng)論推送到數(shù)組中的一個(gè)鍵時(shí),我都會(huì)在我的 api 響應(yīng)中得到空值。我嘗試使用簡(jiǎn)單的 $name['comments'] = $res. 但由于會(huì)有多個(gè)評(píng)論,因此它會(huì)用舊評(píng)論替換新評(píng)論。請(qǐng)幫我解決這些問(wèn)題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(); // =============================================================================
數(shù)組推送到在php中給出空值的鍵
呼喚遠(yuǎn)方
2022-07-16 18:22:50