我在迭代这组产品信息时遇到了麻烦,无法得到每个项目的谷歌电子商务跟踪代码的预期结果。如何将维数减少1。总之-
如何转动这个:
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
)
)
)
这:
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
)
)
对于这个例子,显而易见的答案是:
$array = $array['array'];
但是,假设有多个数组作为第一级:
$array = call_user_func_array('array_merge',$array);
$arr = array(
"withinArray" => array(
"withinMoreArray" => array(
"andEvenMoreArray" => array(
)
)
)
);
$arr = current($arr);
// OR
$arr = $arr['withinArray'];
<?php
// Let's say this is your big array:
/*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
)
)
)*/
$littlearray = $bigarray['array'];
?>