我需要遍歷多維數組幷包裝陣列中數組類型的每個元素。具有動態深度的步行陣列
實例陣列:
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) –