PHP remove specific parent array from specific value recursive -


here's multimensional array :

 array (     [0] => array         (             [id] => 5             [children] => array                 (                     [0] => array                         (                             [id] => 1                             [children] => array                                 (                                     [0] => array                                         (                                             [id] => 2                                         )                                  )                          )                  )          )      [1] => array         (             [id] => 6         )  )  

i'm looking php function remove parent or grand-parent array given "id" value. example, if id == 2, i'd remove closest array key named "children", :

 array (     [0] => array         (             [id] => 5             [children] => array                 (                     [0] => array                         (                             [id] => 1                          )                  )          )      [1] => array         (             [id] => 6         )  ) 

if id == 5, new array :

 array (     [0] => array         (             [id] => 6         )  ) 

or if id == 6, new array :

 array (     [0] => array         (             [id] => 5             [children] => array                 (                     [0] => array                         (                             [id] => 1                             [children] => array                                 (                                     [0] => array                                         (                                             [id] => 2                                         )                                  )                          )                  )          )    ) 

how do maybe recursive function ? appreciate ! ! :)


Comments