Can anyone help me to improve this code? I want to delete array if it already exists. Thanks
if(count($cart['Item']) > 0) {
unset($cart['Item']);
$items['Item'] = array();
$cart = array_merge($cart, $items);
}
if(!empty($cart['Item'])) {
unset($cart['Item']);
}
!empty requires the array item to be both existent and not falsy (e.g. empty)unset will delete the given key from $cartHowever, if you want to replace it with a new, empty array:
$cart['Item'] = array();
No need to do anything else. PHP has a Garbage Collector.
$cart['Item']