从php数组中获取价值

时间:2014-12-04 11:04:56

标签: php

我有一个发货API,它会生成一个名为$ quotereply的变量。

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]之类的值?我无法理解我所看到的内容,是否是数组中的数组?

提前致谢!

2 个答案:

答案 0 :(得分:0)

试试:

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

答案 1 :(得分:0)

它是多维数组,因此您应该遵循array索引键]

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