【发布时间】:2012-04-06 11:20:42
【问题描述】:
对于电子商务,预期的名称值对我有以下批准的代码:
函数 create_example_purchase() {
set_credentials();
$purchase = array(
'name' => 'Digital Good Purchase Example',
'description' => 'Example Digital Good Purchase',
'amount' => '12.00', // sum of all item_amount
'items' => array(
array( // First item
'item_name' => 'First item name',
'item_description' => 'a description of the 1st item',
'item_amount' => '6.00',
'item_tax' => '0.00',
'item_quantity' => 1,
'item_number' => 'XF100',
),
array( // Second item
'item_name' => 'Second Item',
'item_description' => 'a description of the 2nd item',
'item_amount' => '3.00',
'item_tax' => '0.00',
'item_quantity' => 2,
'item_number' => 'XJ100',
),
)
);
return new Purchase( $purchase);
}
我想从购物车中动态获取关联 $purchase 数组中的 $items 数组。
有没有办法生成与上面完全相同的输出?
我的肮脏解决方案,将 $purchase 数组写为字符串,将生成的 $items 数组包含在文件中并包含它 稍后在被调用的脚本中。
帮助表示赞赏。
【问题讨论】:
标签: arrays multidimensional-array paypal-nvp