I'm trying to turn a multidimensional array created by iterating over an array created by a shopping cart:
Array (
[array] => Array (
[0] => Array (
[product_id] => 7
[prod_count] => 1
[price] => 19.99
)
[1] => Array (
[product_id] => 6
[prod_count] => 3
[price] => 19.99
)
[2] => Array (
[product_id] => 5
[prod_count] => 2
[price] => 19.99
)
[3] => Array (
[product_id] => 4
[prod_count] => 4
[price] => 14.99
)
[4] => Array (
[product_id] => 3
[prod_count] => 5
[price] => 19.99
)
)
)
into something like this:
$items = array(
array('product_id'=> $val, 'price'=>$price, 'quantity'=>$prod_count),
array('product_id'=>$val, 'price'=>$price, 'quantity'=>$prod_count),
array('product_id'=>$val, 'price'=>$price, 'quantity'=>$prod_count)
);
So that I can feed it to the google analytics e-commmerce tracking code and echo the code below for each product in the array.
_gaq.push(['_addItem',
'<?php $order_id; ?>', // trans ID **I have this part figured out**
'<?php $product_id; ?>', // SKU/code - required
'', // product name
'', // category or variation
'<?php $price; ?>', // unit price - required
'<?php $prod_count; ?>' // quantity - required
]);
Ive tried a bunch of solutions from SO but none of them seem to work right for my shopping cart array and honestly I'm stumped. Good people of SO please point me in the right direction.
EDIT* Here is my code that creates the multidimensional array in the first place.
$products = array();
for($i=0; $i<sizeof($productsIds); $i++){
$product = explode(":", $productsIds[$i]);
$products[$i]['info'] = $this->Products->getProductById($product[0]);
$products[$i]['count'] = $product[1];
$products[$i]['price_count'] = $product[1]*$products[$i]['info']['product_price'];
$orderarray[$i] = array(
'product_id' => $products[$i]['info']['product_id'],
'prod_count' => $products[$i]['count'],
'price' => $products[$i]['info']['product_price']) ;
Maybe I could change this to create an array better suited for my desired outcome. Just not sure how.