I am trying to create a multidimensional array that is strictly based on this xml template (structure):
<invoice>
<type></type>
<transport></transport>
<items>
<item-ordered>
<name></name>
<quantity></quantity>
</item-ordered>
</items>
</invoice>
I am a php newbie, so i tried to solve it using basic knowledge of php:
//This is from where I get all data for populating my XML/array structure
$products = $params['order']->getProducts();
$prName = array_column($products, 'product_name');
$prQuantity = array_column($products, 'product_quantity');
//Populating arrays with data
$item-ordered = array();
$items = array();
for($i = 0; $i < count($products); $i++) {
$item-ordered = array (
"name" => $prName[$i],
"quantity" => $prQuantity[$i]
);
array_push($items,$item-ordered); //using a hyphen appears to be invalid
)
$invoice = array (
"type" => "code:INVOICE",
"transport" => $customerTransport,
"items" => $items
)
but I run into a problem when trying to use a variable/array name that includes a dash(hyphen).
So my 1st question is whether my solution is right. If it is than I would like to know how do I deal with that hyphen issue. The final array should have exactly the same structure as the XML file showed above, I cannot change the XML file itself.