这是一个多层阵列:
Array ( [0] => Array ( [id] => 5 [children] => Array ( [0] => Array ( [id] => 1 [children] => Array ( [0] => Array ( [id] => 2 ) ) ) ) ) [1] => Array ( [id] => 6 ) )
我正在寻找一个可以从给定的" id"中删除父或祖父数组的PHP函数。值。例如,如果id == 2,我想删除最近的数组,其中包含名为" children"的键,类似于:
Array ( [0] => Array ( [id] => 5 [children] => Array ( [0] => Array ( [id] => 1 ) ) ) [1] => Array ( [id] => 6 ) )
如果id == 5,则新数组将为:
Array ( [0] => Array ( [id] => 6 ) )
或者如果id == 6,新数组将是:
Array ( [0] => Array ( [id] => 5 [children] => Array ( [0] => Array ( [id] => 1 [children] => Array ( [0] => Array ( [id] => 2 ) ) ) ) ) )
我如何使用递归函数执行此操作?我真的很感激一些帮助!谢谢 ! :)