Hello. I have the next array:
Array(
[id] => 1
[children] => Array(
[2] => Array(
[id] => 2
[inactive] => true
[children] => Array(
[4] => Array(
[id] => 4
[children] => Array()
)
)
)
[3] => array(
[id] => 3
[children] => Array(
[5] => Array(
[id] => 5
[inactive] => true
[children] => Array()
)
)
)
)
)
I need to remove elements from this array, which have [inactive] = true. But my problem in the next. I should shift the array elements. Output should be:
Array(
[id] => 1
[children] => Array(
[4] => Array(
[id] => 4
[children] => Array()
)
[3] => array(
[id] => 3
[children] => Array(
)
)
)
)
It is my function. But it removes array element with all his subelements.
public function deleteInactive($userTree)
{
if (!empty($userTree)) {
foreach($userTree['children'] as $userId => &$user) {
if (array_key_exists('inactive', $user)) {
$userTree['children'] += $user['children'];
unset($userTree['children'][$userId]);
$this->deleteInactive($userTree);
break;
}
$this->deleteInactive($user);
}
}
return $userTree;
}
Can you help me to modify this function?
Thank you very much.