好的,所以我有这个数组,我想用它来填充 gaq 电子商务跟踪:
$ga_itemdata = Array ( [0] => Array ( [product_id] => 7 [prod_name] => Pet Driver's License Bag Tag [prod_count] => 2 [price] => 19.99 ) [1] => Array ( [product_id] => 6 [prod_name] => The Driver's License Pet Tag [prod_count] => 1 [price] => 19.99 ) [2] => Array ( [product_id] => 5 [prod_name] => Pet Driver's License Key Chain [prod_count] => 3 [price] => 19.99 ) [3] => Array ( [product_id] => 4 [prod_name] => Pet Driver's License Magnet [prod_count] => 2 [price] => 14.99 ) [4] => Array ( [product_id] => 3 [prod_name] => Pet Driver's License Wallet Card [prod_count] => 3 [price] => 19.99 ) )
我试图用这些变量填充以下代码,然后回显到页面,为数组中的每个项目一次:
_gaq.push(['_addItem',
$order_id, // I have this from another array
$product_id, // SKU/code
$prod_name, // product name
'empty', // category or variation
$price', // unit price
$prod_count // quantity
]);
我有这个 foreach 循环:
foreach($ga_itemdata as $itemnum => $itemarr[0]) {
for($i=0; $i<sizeof($itemarr); $i++){
foreach ($itemarr[$i] as $details[$i]) {
// echo google tracking code
}
}
}
它似乎工作不正常,我坚持下去,任何帮助都会很棒!