第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何糾正 php 中重復(fù)的 json 數(shù)組

如何糾正 php 中重復(fù)的 json 數(shù)組

PHP
精慕HU 2023-11-03 15:28:27
我有以下代碼從 mysql 數(shù)據(jù)庫讀取數(shù)據(jù)。不幸的是我似乎找不到刪除這個(gè)的方法"status": {這是代碼片段// required headersheader("Access-Control-Allow-Origin: *");header("Content-Type: application/json; charset=UTF-8");  // database connection will be here// include database and object filesinclude_once '../config/database.php';include_once '../objects/status.php';  // instantiate database and status object$database = new Database();$db = $database->getConnection();  // initialize object$status = new Status($db);  // query status$stmt = $status->read();$num = $stmt->rowCount();  // check if more than 0 record foundif($num>0){      // status array    $status_arr=array();    $status_arr["status"]=array();      // retrieve our table contents    // fetch() is faster than fetchAll()    // http://stackoverflow.com/questions/2770630/pdofetchall-vs-pdofetch-in-a-loop    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){        // extract row        // this will make $row['name'] to        // just $name only        extract($row);          $status_item = array(            "id" => $status_id,            "name" => html_entity_decode($status_name),            "created" => $status_created,            "modified" => $status_modified,            "state" => $status_state        );        array_push($status_arr["status"], $status_item);    }      // set response code - 200 OK    http_response_code(200);      // show status data in json format    echo json_encode(        array("response_code" => 0, "response_message" => "Request processed successfully", "status" => $status_arr)    );}else{      // set response code - 404 Not found    http_response_code(404);      // tell the user no status found    echo json_encode(        array("response_code" => 1, "response_message" => "No status found.")    );請(qǐng)注意,在所需的輸出中不應(yīng)有 "status": {},而應(yīng)僅具有 "status": []。我應(yīng)該對(duì)上面提供的代碼進(jìn)行哪些修改?
查看完整描述

1 回答

?
MMTTMM

TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊

echo json_encode(

  array(

    "response_code" => 0,

    "response_message" => "Request processed successfully",

    "status" => $status_arr["status"]

  )

);


查看完整回答
反對(duì) 回復(fù) 2023-11-03
  • 1 回答
  • 0 關(guān)注
  • 163 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)