Get associative array values into variables,which is in string format from cookies
Use json_decode($getcart, true);
. Here true
parameter in json_decode() convert JSON
to array. Without true
parameter it is converted to array()
of object
.
$getcart = '[{"id":"7","quantity":"3","price":1500,"title":"Shoes"},{"id":"9","quantity":"4","price":1290,"title":"Shirt"}]';$arr = json_decode($getcart, true);print '<pre>';foreach($arr as $val){ print_r($val); //print $val['id']; //print $val['quantity']; //print $val['price']; //print $val['title'];}print '</pre>';