Home > Backend Development > PHP Tutorial > How to use cookies to store multidimensional arrays in PHP

How to use cookies to store multidimensional arrays in PHP

WBOY
Release: 2016-07-25 09:05:35
Original
1163 people have browsed it
  1. //Save
  2. $arr = array(1,2,3);
  3. $arr_str = serialize($arr);
  4. setcookie("a",$arr_str);
  5. //Take out
  6. $ arr_str = $_COOKIE['a'];
  7. $arr = unserialize($arr_str);
Copy code

Method 2: Set a multi-key value cookie, please note that the key value must be given

  1. $arr = array(1,2,3);
  2. setcookie("a[0]", $arr[0]);
  3. setcookie("a[1]", $arr[1] );
  4. setcookie("a[2]", $arr[2]);
Copy code

Note: The above method is copied from elsewhere. I tried the first method and it was successful. It is also more convenient. I have not tried the second method, so please test it more.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template