我使用的是Laravel 5.3
。
我有一个multidimensional array
,如下所示:
Array
(
[id] => 37141
[last_done_on] => []
[children] => Array
(
[0] => NULL /* This must be removed */
[1] => Array
(
[id] => 37142
[last_done_on] => Array()
[children] => Array()
)
[2] => Array
(
[id] => 37143
[last_done_on] => Array()
[children] => Array
(
[0] => Array
(
[id] => 37144
[last_done_on] => Array()
[children] => Array()
)
[1] => Array
(
[id] => 37145
[last_done_on] => Array()
[children] => Array()
)
)
)
[3] => Array
(
[id] => 37157
[last_done_on] => Array()
[children] => Array
(
[0] => Array
(
[id] => 37158
[last_done_on] => Array()
[children] => Array()
)
[1] => Array
(
[id] => 37159
[last_done_on] => Array()
[children] => Array
(
[0] => NULL /* This must be removed */
)
)
)
)
)
)
我想把remove
乘以elements
,得到NULL
,结果应该是:
Array
(
[id] => 37141
[last_done_on] => []
[children] => Array
(
[0] => Array
(
[id] => 37142
[last_done_on] => Array()
[children] => Array()
)
[1] => Array
(
[id] => 37143
[last_done_on] => Array()
[children] => Array
(
[0] => Array
(
[id] => 37144
[last_done_on] => Array()
[children] => Array()
)
[1] => Array
(
[id] => 37145
[last_done_on] => Array()
[children] => Array()
)
)
)
[2] => Array
(
[id] => 37157
[last_done_on] => Array()
[children] => Array
(
[0] => Array
(
[id] => 37158
[last_done_on] => Array()
[children] => Array()
)
[1] => Array
(
[id] => 37159
[last_done_on] => Array()
[children] => Array
(
)
)
)
)
)
)
如何做到这一点?
4条答案
按热度按时间bprjcwpo1#
在集合中,使用筛选器
pbossiut2#
如果你想删除
null
值而不是空数组,你可以这样做:希望这有帮助!
0md85ypi3#
有两个选项可供用途:
或
将删除所有具有空值的键
dtcbnfnu4#
试试这个: