我正在尝试从Cookie中打印出我的数组。但是,当我运行脚本时,我收到此错误。 注意:C:/ Xampp / etc中的数组转换为字符串。 值:数组
这是我的代码:
<?php
$NewCookie = "NewCookie";
$NewCookieArray = array("CookieValueOne <br>", "CookieValueTwo<br>", "CookieValueThree<br>");
setcookie($NewCookie, json_encode($NewCookieArray),time() + (3600*24));
?>
<html>
<body>
<?php
if (!isset($_COOKIE[$NewCookie]))
{
echo "Cookie named '" . $NewCookie . "' is not set!<br>";
}
Else
{
echo "Cookie named '" . $NewCookie . "' is set!<br>";
echo "Value is: " . $NewCookieArray = json_decode($_COOKIE[$NewCookie]);
}
&GT;
答案 0 :(得分:1)
更改此行:
echo "Value is: " . $NewCookieArray = json_decode($_COOKIE[$NewCookie]);
有了这个:
echo "Value is: <pre>" . print_r(json_decode($_COOKIE[$NewCookie],1)) . "</pre>";