private function cleanupCartsArray(&$cartsArray)
    {
        if ($cartsArray && count($cartsArray) > 0) {
            // handle cartsArray count is > 1
            foreach ($cartsArray as $index => $cart) {
                // delete expired carts
                if ($cart->getChanged()->getTimestamp() < strtotime(static::EXPIRY_MONTHS . ' months ago')) {
//                    $this->em->remove($cart);
                    continue;
                }

                // dont delete first element, since this is the current cart
                if ($index === 0) {
                    continue;
                }
                // remove duplicated carts
//                $this->em->remove($cart);
            }
        }
    }
private function cleanupCartsArray(&$cartsArray)
    {
        if ($cartsArray && count($cartsArray) > 0) {
            // handle cartsArray count is > 1
            foreach ($cartsArray as $index => $cart) {
                // delete expired carts
                if ($cart->getChanged()->getTimestamp() < strtotime(static::EXPIRY_MONTHS . ' months ago')) {
//                    $this->em->remove($cart);
                    continue;
                }

                // dont delete first element, since this is the current cart
                if ($index === 0) {
                    continue;
                }
                // remove duplicated carts
//                $this->em->remove($cart);
            }
        }
    }
private function cleanupCartsArray ( & $ cartsArray ) { if ( $ cartsArray && count ( $ cartsArray ) > 0 ) { // handle cartsArray count is > 1 foreach ( $ cartsArray as $ index => $ cart ) { // delete expired carts if ( $ cart -> getChanged ( ) -> getTimestamp ( ) < strtotime ( static :: EXPIRY_MONTHS . ' months ago' ) ) { //                    $this->em->remove($cart); continue ; } // dont delete first element, since this is the current cart if ( $ index === 0 ) { continue ; } // remove duplicated carts //                $this->em->remove($cart); } } }
removes all elements from database but the first

@param $cartsArray
removes all elements from database but the first