How to recursively filter a multidimensional array
I have a five dimensional array ,
I would like to filter items in a different levels ,
every item that it's url equals to "MUSET REMOVED" should be removed .
$menu = array(
"System" => array(
"VisibleName" => "System",
"Children" => array(
"Access" => array(
"VisibleName" => "Access",
"Url"=>"/sth",
"Children" => array(
"Groups" => array(
"VisibleName" => "Groups",
"Url" => "/Groups"
),
"LockoutTable" => array(
"VisibleName" => "LockoutTable",
"Url" => "MUST REMOVED"
),
"Password" => array(
"VisibleName" => "Password",
"Url" => "MUST REMOVED"
),
),
"users" => array(
"VisibleName" => "users",
"Url"=>"MUST REMOVED",
"Children" => array()
),
"roles" => array(
"VisibleName" => "Access",
"Url"=>"/roles",
"Children" => array()
)
),
)
),
);
$filtered_menu = array();
foreach ($menu as $level_one_k => $level_one_v) {
$level_two_filtered=array();
foreach($level_one_v as $level_two_k=>$level_two_v){
// i dont know How to continue this
// it must filter every item that its Url == "MUST REMOVED"
}
$filtered_menu[$level_one_k]=$level_two_filtered;
}
I don't know How to handle filter of such complicated array .
the expected result would be like this:
$menu = array(
"System" => array(
"VisibleName" => "System",
"Children" => array(
"Access" => array(
"VisibleName" => "Access",
"Url"=>"/sth",
"Children" => array(
"Groups" => array(
"VisibleName" => "Groups",
"Url" => "/Groups"
),
),
"roles" => array(
"VisibleName" => "Access",
"Url"=>"/roles",
"Children" => array()
)
),
)
),
);