I'm storing data in cookie using serialize/unserialize function. Unserialize function does not working when i add new item to array.
Code
$storedArr = array();
if(isset($_REQUEST['sendProductId'])){
$newItem = $_REQUEST['sendProductId'];
$storedArr[] = $_COOKIE['productID'];
array_push($storedArr, $newItem);
$cookie_name = 'productID';
setcookie($cookie_name, serialize($storedArr), time() + (86400 * 30));
}
$cookieData = $_COOKIE['productID'];
$data = unserialize($cookieData);
print_r($data);
Response on Single array index
Array ( [0] => [1] => 50 )
Response on when adding new item to array
Array ( [0] => a:2:{i:0;N;i:1;s:2:"50";} [1] => 50 )
Please guide me where i'm wrong. Thanks