How to get the customizable option of last added to cart product in Magento 2

<?php customizable option of last added to cart product in Magento 2

customizable option of last added to cart product in Magento 2expoundsofttechsolution customizable option of last added to cart product in Magento 2

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$cart = $objectManager->get(‘\Magento\Checkout\Model\Cart’);

$itemsCollection = $cart->getQuote()->getItemsCollection();

$itemsVisible = $cart->getQuote()->getAllVisibleItems();

$items = $cart->getQuote()->getAllItems();

$max = 0;
$lastItem = null;

foreach ($items as $item){
if ($item->getId() > $max) {
$max = $item->getId();
$lastItem = $item;
}

if ($lastItem){
$options = $lastItem->getProduct()->getTypeInstance(true)->getOrderOptions($lastItem->getProduct());
$customOptions = $options[‘options’];
if (!empty($customOptions)) {
foreach ($customOptions as $option) {
echo $optionTitle = $option[‘label’].’: ‘.$optionValue = $option[‘value’].’
‘;
}
}
}
?>