Delete product from the cart in magento

        $pro_id = $your_product_id;
        $product = Mage::getModel('catalog/product')->load($pro_id);
        if ($product->getData('type_id') == "configurable"):

         $attribute_id = $your_attribute_id;
         $attribute_valid = $your_attribute_valid;
       
          try{

                $cartHelper = Mage::helper('checkout/cart');
                $items = $cartHelper->getCart()->getItems();

                foreach($items as $item):
                if($item->getProduct()->getId() == $pro_id):
                
                $att_id_arr=array();
                $att_vid_arr=array();

                $attribute_data= $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
                $att_kv=$attribute_data['info_buyRequest']['super_attribute'];
                foreach($att_kv as $att_id=>$att_vid){
                 $att_id_arr[]= $att_id;
                 $att_vid_arr[]= $att_vid;
                }

                if(in_array($attribute_id, $att_id_arr) && in_array($attribute_valid, $att_vid_arr)):

                $itemQuantity = $item->getQty();
               
                if($itemQuantity == 1):
     
                $itemId = $item->getItemId();
                $cartHelper->getCart()->removeItem($itemId)->save();

                else:

                $item->setQty($itemQuantity-1);
                $cartHelper->getCart()->save();

                endif;  
                
                
                break;
                endif;
                endif;
                endforeach;

            }catch (Exception $e) {
                
             }  


          else:

               try{

                $cartHelper = Mage::helper('checkout/cart');
                $items = $cartHelper->getCart()->getItems();

                foreach($items as $item):
                if($item->getProduct()->getId() == $pro_id):
                $itemQuantity = $item->getQty();
               

                if($itemQuantity == 1):
     
                $itemId = $item->getItemId();
                $cartHelper->getCart()->removeItem($itemId)->save();

                else:

                $item->setQty($itemQuantity-1);
                $cartHelper->getCart()->save();

                endif;  
                
                
                break;
                endif;
                endforeach;


                
               } catch (Exception $e) {
               
             }  

        endif;