我需要遍历多维数组并包装阵列中数组类型的每个元素。具有动态深度的步行阵列
实例阵列:
Array
(
[product_id] => 1
[product_name] => Jack Daniel's
[sku] => 0
[size] => 700
[case_size] => 6
[description] => A spirit from USA
[status] => ACTIVE
[created] => 2016-10-02 23:13:17
[modified] => 2016-10-02 23:13:17
[packs] => Array
(
[product_pack_id] => 1
[store_id] => 1
[product_id] => 1
[pack_size] => 1
[created] => 2016-10-02 23:13:17
[modified] => 2016-10-02 23:13:17
[barcodes] => Array
(
[product_barcode_id] => 1
[product_id] => 1
[store_id] => 1
[product_pack_id] => 1
[barcode] => 82184045954
[created] => 2016-09-29 06:48:54
[modified] => 2016-09-29 06:48:54
)
)
)
但该阵列的深度可以在3个阵列深至无限变化。
我需要包装每个n深度在阵列中,例如包=>需要被包裹在一个阵列,但也包=>条形码需要被包裹在一个阵列给我以下结果:
Array
(
[product_id] => 1
[product_name] => Jack Daniel's 700ml
[sku] => 0
[size] => 700
[case_size] => 6
[description] =>
<p>Jack Daniel's is a sour mash charcoal filtered American whiskey, which makes it different to it cousin, Bourbon. The mash is made up of 80% corn, 12% rye and 8% malt. Then filtered through 10 feet of charcoal to mellow out the flavours of the malt and the corn, which gives it a distinctive smoky flavour.</p>
[status] => ACTIVE
[created] => 2016-10-02 23:13:17
[modified] => 2016-10-02 23:13:17
[packs] =>
[0] => Array
(
[product_pack_id] => 1
[store_id] => 1
[product_id] => 1
[pack_size] => 1
[created] => 2016-10-02 23:13:17
[modified] => 2016-10-02 23:13:17
[barcodes] =>
[0] => Array
(
[product_barcode_id] => 1
[product_id] => 1
[store_id] => 1
[product_pack_id] => 1
[barcode] => 82184045954
[created] => 2016-09-29 06:48:54
[modified] => 2016-09-29 06:48:54
)
)
)
但是数组的深度是可变的,例如上面的深度为3,但是它明天可以增长到4的深度。
所有你想要做的就是用单个元素'[array]'替换每个嵌套关联'数组'或者可能涉及到一些聚合? – shudder
哟狗,我听说你喜欢数组,所以这里有一个数组数组,以便您可以排列数组,同时排列数组。 - 但是,严肃地说,你能澄清你的意思吗? – Jhecht
[有没有办法在不知道深度的情况下遍历多维数组?](http://stackoverflow.com/questions/10928993/is-there-a-way-to-loop-through-a-多维数组不知道它的dep) –