php multidimensional array as name value pair
- by Ayad Mfs
For ecommerce, that expected name value pair I have the following approved code:
function 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);
}
I would like to get $items Array inside associative $purchase array dynamically from shipping cart.
Is there a way to generate exactly the same output above?
My dirty solution, to write $purchase array as string inclusive the generated $items array in a file and include it
later in the called script.
Help appreciated.