cookieĬÈϲ»ÄÜ´æÊý×飬ËùÒÔÏÂÃæµÄд·¨ÊÇ´íÎóµÄ¡£
<?php
$arr = array(1,2,3);
setcookie('a',$arr);
$arr = array(1,2,3);
setcookie('a',$arr);
?>
±¨´íÈçÏ£º
Warning: setcookie() expects parameter 2 to be string, array given in
µ«ÊÇPHP¿ÉÒÔ°ÑͬÃûÇÒºóÃæÒÔ[]½áβµÄcookie½âÎöΪÊý×é¡£ÔÚphpÀïÃæʵÏÖcookie´æÊý×éµÄ·½·¨ÈçÏ£º
·½·¨Ò»£ºÏÈÓÃserializeÐòÁл¯Êý×飬ÔÙ´æÈëCOOKIE ,¶Á³öÀ´Ê±ÓÃunserializeµÃµ½ÔÀ´µÄÊý×é
//´æÈë
$arr = array(1,2,3);
$arr_str = serialize($arr);
setcookie("a",$arr_str);
//È¡³ö
$arr_str = $_COOKIE['a'];
$arr = unserialize($arr_str);
//´æÈë
$arr = array(1,2,3);
$arr_str = serialize($arr);
setcookie("a",$arr_str);
//È¡³ö
$arr_str = $_COOKIE['a'];
$arr = unserialize($arr_str);
·½·¨¶þ£ºÉ趨¶à¼üÖµcookie£¬×¢Òâ±ØÐë¸ø¼üÖµ
$arr = array(1,2,3);
setcookie("a[0]", $arr[0]);
setcookie("a[1]", $arr[1]);
setcookie("a[2]", $arr[2]);
$arr = array(1,2,3);
setcookie("a[0]", $arr[0]);
setcookie("a[1]", $arr[1]);
setcookie("a[2]", $arr[2]);
½á¹û£ºÊý×éËùÓÐÔªËض¼´æµ½ÁË¡£
Êý×鳤¶È £º3
Array ( [0] => 1 [1] => 2 [2] => 3 )
ÒÔÏÂд·¨ÊÇ´íÎóµÄ£º
$arr = array(1,2,3);
setcookie("a[]", $arr[0]);
setcookie("a[]", $arr[1]);
setcookie("a[]", $arr[2]);
$arr = array(1,2,3);
setcookie("a[]", $arr[0]);
setcookie("a[]", $arr[1]);
setcookie("a[]", $arr[2]);
½á¹û£ºÖ»´æÁË×îºóÒ»¸öÔªËØ
Êý×鳤¶È £º1
Array ( [0] => 3 )