试图从cookie中打印出一个数组

时间:2016-04-10 18:28:06

标签: php arrays cookies

我正在尝试从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;

1 个答案:

答案 0 :(得分:1)

更改此行:

  echo "Value is: " . $NewCookieArray = json_decode($_COOKIE[$NewCookie]);

有了这个:

  echo "Value is: <pre>" . print_r(json_decode($_COOKIE[$NewCookie],1)) . "</pre>";