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

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

如何用它的名字來分隔兩個數組

如何用它的名字來分隔兩個數組

PHP
ABOUTYOU 2022-09-12 12:51:19
我正在獲取 json 中的數組"sub": {            "insert_id": [                161,                162,                163,                164            ],            "venue_id": [                "21",                "3",                "5",                "6"            ]        }像這樣,我現在把它放到php變量中,我想要$allidinsert_id :[161,162,163,164] and venue_id :[21,3,5,6]
查看完整描述

3 回答

?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

您需要先使用,然后才能以所需的任何方式使用數據json_decode


示例(注意:不是最干凈的做事方式):


/* Decode JSON */

$data = '{"sub":{"insert_id":[161,162,163,164],"venue_id":["21","3","5","6"]}}';

$subData = json_decode($data,true);




/* Just Loop Through Values */

foreach ($subData['sub']['insert_id'] as $sub){

    echo ("<li>$sub</li>");


}



/* Create New Json */

$insertIdJson = json_encode($subData['sub']['insert_id']);

$venueIdJson = json_encode($subData['sub']['venue_id']);

echo ("Insert IDs: $insertIdJson </br>");

echo ("Venue IDs :$venueIdJson </br>");



/* Create Array Of insert_id */

$insertIdArray = json_decode(json_encode($subData['sub']['insert_id']),true);   

$venueIdArray = json_decode(json_encode($subData['sub']['venue_id']),true); 


var_dump($insertIdArray);

echo("</br>");

var_dump($venueIdArray);


查看完整回答
反對 回復 2022-09-12
?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

讓我們考慮$json結果變量中的 json 響應


$json_result = "sub": {

                    "insert_id": [

                        161,

                        162,

                        163,

                        164

                    ],

                    "venue_id": [

                        "21",

                        "3",

                        "5",

                        "6"

                    ]

                }


$result = json_decode($json_result, true);

$insert_id = $result["sub"]["insert_id"];

$venue_id = $result["sub"]["venue_id"];


echo "insert_id";

print_r($insert_id);


echo "venue_id";

print_r($venue_id);


查看完整回答
反對 回復 2022-09-12
?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

you can use this.


$jsonData = '{"sub":{"insert_id":[161,162,163,164],"venue_id":["21","3","5","6"]}}';

$json_result = json_decode($jsonData,true);


$insertId = $json_result["sub"]["insert_id"];

$venueId = $json_result["sub"]["venue_id"];


echo "<pre>";

print_r($insertId);

echo "<br>";

print_r($venueId);


查看完整回答
反對 回復 2022-09-12
  • 3 回答
  • 0 關注
  • 98 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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