I know how to set and get session value in magento 2. Here is what I do:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$mysession = $objectManager->create('Magento\Customer\Model\Session');
$mysession->setMyTestValue('testsession');
$mysession->getMyTestValue();
It works fine.
But I want multiple session value in an array; In simple PHP I've achieved this in following way:
**//Set session in an array**
<?php
foreach ($_productCollection as $_product):
$_SESSION ['mytestvalues'] = array ();
array_push($_SESSION['mytestvalues'], $_product->getEntityId());
endforeach;
?>
/**/Get session array**
<?php print_r($_SESSION['mytestvalues']); ?>
Same thing I want to achieve in Magento 2. How to achieve this in magento 2?