I have a problem with remove items from an array with object, the same code run in other app. After looping the array $categories
should be empty. The code bellow removes all children categories then removes the parent category if the user pass the second parameter as TRUE, if the parent doesn't have a child then remove it only.
//the $id of the category to be removed
// $remove_children is state if you accept removing children categories
function remove_category($id = null, $remove_children = false) {
if ($this->MD->is_category($id) && is_bool($remove_children)) {
//get all children category
$children = $this->get_children_categories($id);
if (!$children) {
return $this->MD->remove($id, $this->categories_table);
} else {
if ($remove_children && is_array($children)) {
unset($children['parent_category']);
foreach ($children as $child) {
$removed = $this->MD->remove($child->id, $this->categories_table);
if ($removed) {
//problem here
unset($child);
}
}
//the $children is not empty after remove all the items
if (empty($children)) {
return $this->MD->remove($id, $this->categories_table);
} else {
return false;
}
} else {
return false;
}
}
} else {
return false;
}
}