将项添加到数组

时间:2012-08-25 17:21:56

标签: php arrays paypal product

如何向此阵列添加其他项目:

$item = array('Quantity' => 1,
              'Product' => array ('Name' => 'name of test product',
                                  'UnitPrice' => array ('Gross' => 10000,
                                                        'Net' => 7800,
                                                        'Tax' => 22,
                                                        'TaxRate' => '22',
                                                        'CurrencyCode' => 'PLN')
                                 )
             );
  

数组([数量] => 1 [产品] =>数组([名称] =>测试名称   产品[UnitPrice] =>数组([Gross] => 10000 [Net] => 7800 [Tax] =>   22 [TaxRate] => 22 [CurrencyCode] => PLN)))

2 个答案:

答案 0 :(得分:1)

您需要稍微更改结构才能执行此操作:

$item = array(  
    0 => array (
        'Name' => 'name of test product',
        'UnitPrice' => array (
            'Gross' => 10000, 'Net' => 7800, 'Tax' => 22, 'TaxRate' => '22',   'CurrencyCode' => 'PLN',
         )
         'Quantity' => 1,
     ),
     1 => array (
         'Name' => 'name of test product 2',
         'UnitPrice' => array (
             'Gross' => 10000, 'Net' => 7800, 'Tax' => 22, 'TaxRate' => '22',   'CurrencyCode' => 'PLN',
          )
          'Quantity' => 3,
     ),
 );

答案 1 :(得分:0)

示例

$items = array();
$items[] = array('Quantity' => 1,
              'Product' => array ('Name' => 'name of test product',
                                  'UnitPrice' => array ('Gross' => 10000,
                                                        'Net' => 7800,
                                                        'Tax' => 22,
                                                        'TaxRate' => '22',
                                                        'CurrencyCode' => 'PLN')
                                 )
             );
$items[] = array('Quantity' => 1,
              'Product' => array ('Name' => 'name of test product',
                                  'UnitPrice' => array ('Gross' => 10000,
                                                        'Net' => 7800,
                                                        'Tax' => 22,
                                                        'TaxRate' => '22',
                                                        'CurrencyCode' => 'PLN')
                                 )
             );
$items[] = array('Quantity' => 1,
              'Product' => array ('Name' => 'name of test product',
                                  'UnitPrice' => array ('Gross' => 10000,
                                                        'Net' => 7800,
                                                        'Tax' => 22,
                                                        'TaxRate' => '22',
                                                        'CurrencyCode' => 'PLN')
                                 )
             );
...

然后你可以这样做:

foreach ($items as $item){
    some_function_on_paypal($item); // call your function and execute the $item. 
    // it won't change paypal structure.
}