在Cookie中存储来自Javascript的二维数组

First of all, thanks to everyone that's reading that and trying to help me!

I got an online shop and i have a bi-dimensional array with the products like that:

 1. $arrayProducts[id][0] -> id
 2. $arrayProducts[id][1] -> product name
 3. $arrayProducts[id][2] -> price

etc..

I know isn't the best way to do the system, but it's done like that.

Now, I want to store that bi-dimensional array in a cookie, because what I want to do is to store the cart from the user if they go away from my page, and load that again when they come back.

I think the best way to do it is with cookie, but I don't know if I should do a json_encode and json_decode with that bi-dimensional array, or what is the best way to fix my problem.

Before saving your data to cookie stringify your array.

var x = JSON.stringify(yourarrayvar);

then save x in cookie.

You can use php session

session_start();
$_SESSION['products'] = $arrayProducts;

after refresh of the page you will still have products array in $_SESSION array.