我有一个多维的Laravel集合称为事务。当作为数组输出时,它看起来像这样:
的print_r(事务 - >指定者())
Array
(
[0] => Array
(
[id] => 2
[name] => Level 1
[subcategories] => Array
(
[0] => Array
(
[id] => 3
[name] => Level 2
[transaction_reference] => Array
(
[0] => Array
(
[id] => 1
[name] => Level 3
[children] => Array
(
[id] => 4
[name] => Level 4
)
)
[1] => Array
(
[id] => 2
[name] => Level 3
[children] => Array
(
[id] => 5
[name] => Level 4
)
)
)
)
)
)
)
在第2级,有一个名为“transaction_reference”的数组,它包含两个元素 - 每个元素都包含一个元素。我需要合并这两个元素,因此transaction_reference只包含一个元素,而这个元素又包含两个元素。
换句话说,我需要结果类似于以下内容:
Array
(
[0] => Array
(
[id] => 2
[name] => Level 1
[subcategories] => Array
(
[0] => Array
(
[id] => 3
[name] => Level 2
[transaction_reference] => Array
(
[0] => Array
(
[id] => 1
[name] => Level 3
[children] => Array
(
[id] => 4
[name] => Level 4
)
(
[id] => 5
[name] => Level 4
)
)
)
)
)
)
)
我尝试过以各种格式使用flatten()
,但似乎无法满足我的要求。
这可能吗?
由于