2014-12-04 152 views
0

我有一個運輸API,它產生一個名爲$ quotereply的變量。從php數組獲得價值

的print_r($ quotereply)給了我下面的輸出:

Array ([replycode] => 200 [replymessage] => success [replytype] => quote [quote] => Array ([services] => Array ([noofservices] => 2 [service1] => Array ([name] => TestService1Before12am [description] => Test Service 1 Before 12am [carrier] => Camel [price] => 10 [vat] => 0 [vat_rate] => 0 [insurance_cost] => 0 [insurance_cover] => 0) [service2] => Array ([name] => TestService2Anytime [description] => Test Service 2 Anytime [carrier] => Pigeon [price] => 5 [vat] => 0 [vat_rate] => 0 [insurance_cost] => 0 [insurance_cover] => 0))) [custom] => Array ([data] => [orderid] =>)) 

我的問題是,我怎麼能提取值,如從這個[noofservices]?我無法真正理解我所看到的內容,它是一個數組內的數組嗎?

在此先感謝!

+0

你能後的格式化輸出,而不是一個長行,所以我們可以看到嵌套結構? – Barmar 2014-12-04 11:06:46

回答

0

只是嘗試:

$quotereply['quote']['services']['noofservices'] 
+0

這工作完美。謝謝,當計時器耗盡時,我會接受答案! – Lee 2014-12-04 11:09:24

+0

@Lee不客氣 – hsz 2014-12-04 11:09:44

0

它是多維數組,所以你應該遵循array索引鍵]

echo $quotereply["quote"]["services"]["noofservices"];