我正在为Shopify开发一个配送服务应用程序,我的回调URL有这个JSON post,使用json_decode
将其转换成数组。我想汇总的值是克
,把它放入变量中,然后使用if ($weight <= $maxweight)
与另一个变量的值进行比较。
{
"rate": {
"items": [
{
"name": "My Product 3",
"sku": null,
"quantity": 1,
"grams": 1000,
"price": 2000,
"vendor": "TestVendor",
"requires_shipping": true,
"taxable": true,
"fulfillment_service": "manual"
},
{
"name": "My Product 1",
"sku": null,
"quantity": 1,
"grams": 500,
"price": 1000,
"vendor": "TestVendor",
"requires_shipping": true,
"taxable": true,
"fulfillment_service": "manual"
},
{
"name": "My Product 2",
"sku": null,
"quantity": 1,
"grams": 2000,
"price": 3000,
"vendor": "TestVendor",
"requires_shipping": true,
"taxable": true,
"fulfillment_service": "manual"
}
],
"currency": "CAD"
}
}
foreach
循环来实现,但是将array_map
与array_sum
耦合在一起可以更快地产生相同的结果。 - Giacomo1968