The cookie cannot be stored in an array by default, so the following notation is incorrect.
The error is as follows:
Warning:setcookie () expects parameter 2 to is string, array given in
But PHP can parse the array with the same name and the cookie that ends with []. The following methods are implemented in PHP to store arrays in cookies:
Method One: First use serialize serialization array, and then deposit the cookie, read out with Unserialize to get the original array
Method Two: Set the multi-key value cookie, note must give the key value
Copy the Code code as follows:
$arr = Array (+/-);
Setcookie ("a[0]", $arr [0]);
Setcookie ("a[1]", $arr [1]);
Setcookie ("a[2]", $arr [2]);
Result: all elements of the array are saved.
Array Length: 3
Array ([0] = 1 [1] = 2 [2] = 3)
The following wording is incorrect :
Copy the Code code as follows:
$arr = Array (+/-);
Setcookie ("a[]", $arr [0]);
Setcookie ("a[]", $arr [1]);
Setcookie ("a[]", $arr [2]);
Result: only the last element is saved
Array Length: 1
Array ([0] = 3)
http://www.bkjia.com/PHPjc/327414.html www.bkjia.com true http://www.bkjia.com/PHPjc/327414.html techarticle The cookie cannot be stored in an array by default, so the following notation is incorrect. The error is as follows: Warning:setcookie () expects parameter 2 to is string, array given in but PHP can put the same name and later ...