0
私は以下のような配列を持っていますが、達成したいのは基本的に@attributesとAddressSopのようなキーを削除し、それらをすべて1レベルにして親キーと配列を削除しますが、キーの値のペアはアレイを別のレベルのキーで移動する
[Addresses] => Array
(
[0] => Array
(
[AddrCountry] => US
[AddrLine1] => Test Street
[AddrLine2] => Test
[AddrLine3] => Test
[AddrName] => Mr John Doe
[AddrEmail] => [email protected]
[AddrMasterPriceBook] =>
[AddrMobile] => 123132142242
)
[1] => Array
(
...
)
)
元の配列の外観です。どんな助けも素晴らしいでしょう。
[Addresses] => Array
(
[0] => Array
(
[@attributes] => Array
(
[AddrCountry] => US
[AddrLine1] => Test Street
[AddrLine2] => Test
[AddrLine3] => Test
[AddrName] => Mr John Doe
)
[AddressSOP] => Array
(
[@attributes] => Array
(
[AddrEmail] => [email protected]
[AddrMasterPriceBook] =>
[AddrMobile] => 123132142242
)
)
)
[1] => Array
(
[@attributes] => Array
(
[AddrCountry] => US
[AddrLine1] => Test Street
[AddrLine2] => Test
[AddrLine3] => Test
[AddrName] => Mr John Doe
)
[AddressSOP] => Array
(
[@attributes] => Array
(
[AddrEmail] => [email protected]
[AddrMasterPriceBook] =>
[AddrMobile] => 123132142242
)
)
)
)
:あなたはそれを再帰的になりたい場合は、あなたがこのような何かを行うことができます
? – RhoVisions
私はこれを疲れましたが、重複しているためいくつかのキーを削除します:function filterArray(array $ array){ $ values = []; foreach(配列$ key => $ level){ if(is_array($ level)){ $ values = array_merge($ values、filterArray($ level)); } else { $値[$ key] = $ level; } } return $ values; } –
他の人も同様に知りたいと思うので、あなたの質問を修正する方が良いです。さらに、複数行のコードはコメントで読むのが難しいです。 – RhoVisions