所以我在這裏是從我的PHP cURL的JSON響應,所以我試圖根據location
獲取特定的數組組合,這取決於identifier
的值在哪裏檢查。如何獲得一個對象內的特定數組集合
{
"status": "SUCCESS",
"response": {
"offset": 0,
"max": 50,
"count": 2,
"locations":[
{
"identifier":"54320",
"id": 503892,
"name":"The Foo"
},
{
"identifier":"54321",
"id": 503893,
"name":"The Bar"
}
]
}
這是我迄今爲止所做的和我正在嘗試做的。所以我已經解析了上面的json並將其放在foreach中。注意標識符並不總是int
它也可以是string
。
$parsed_json = json_decode($phpCurlResponse, true);
$parsed_json = $parsed_json["response"]["locations"];
foreach($parsed_json as $key => $pj){
if($pj['identifier'] == "54320"){
echo $pj['name'].' & '.$pj['id'];//this should display The Foo & 503892
}
}
我已經試過這一個,它只能看到array
第一組locations
下,但是當我在identifier
值更改從54321
到112233
響應將是Identifier do not exist.
你可以幫我,如何實現這一目標。
您確定存在標識符爲「112233」_does_的位置嗎?有了迄今爲止所提供的信息,所有工作都按預期工作!? – Jeff
我第二次來@Jeff,你確定你正在得到一個屬性爲'112233'的子數組嗎? – idelara
@jeff hi mate!我再次檢查它,現在正在工作..我刪除了其他因爲它沒有必要我想? .. – camdev