Simple idea, really shopping cart far more complex than this, suitable for beginners, easy to understand
$result _arr = Here is the query result, or data, or string;
Analog data: Array ([0] = = Array ([id] = = 40920435 [title] = 42432 [Addtime] = 2018-02-08 09:22:37 [content] = 432432 [PHOTO] = 2018-02-08/5a7ba65d89746.jpg))
$result = Serialize ($result _arr); Array must be serialized
After serialization: A:1:{i:0;a:5:{s:2: "id"; s:8: "40920435"; s:5: "title"; s:5: "42432"; s:7: "Addtime"; s:19: "2018-02-08 09:22:37"; s:7 : "Content"; s:6: "432432"; s:5: "Photo"; s:28: "2018-02-08/5a7ba65d89746.jpg";}}
$id = Mark, can be the data unique ID, can also be a name and so on, convenient for later use, here I use the Product ID;
Setcookie ("buycart[". $id. "]", $result, Time () +20),//20 is seconds, customizable;
The above is the name and value of the set shopping cart cookie;
The following is the acquisition of data in the shopping cart;
$cookies _arr = $_cookie[' Buycart ');
foreach ($cookies _arr as $name = + $v) {
Print_r ($name);//buycart[". $id."], the output is the value of $id;
Print_r (Unserialize ($v));//deserialization, output is an array
}
PHP Cookie Shopping cart usage ideas