2016-04-10 19 views
0

Array'ımı bir çerezden yazdırmaya çalışıyorum. Ancak komut dosyasını çalıştırdığımda bu hatayı alıyorum. Uyarı: C dize dönüştürme Dizisi:/xampp/vs .. Değer:?Bir çerezi bir dizi yazdırmaya çalışmak

<?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]); 
} 

>

+0

Tam olarak ne diyor. Bir diziniz var, sadece onu ekleyemezsiniz. Test için print_r' veya 'var_dump' ve üretim için bir çeşit foreach' döngüsünü veya benzerlerini deneyin. –

+0

'json_decode()' bir JSON Dizesini alır ve bir PHP dizisine veya bir PHP nesnesine dönüştürür. Bu işe yaradıramazsınız, 'birArray' ya da echo $ anObject ' – RiggsFolly

cevap

1

Değişim bu hat:

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

Bu benim kodudur

Bununla bir tane:

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

Evet! Sorun sonuçta aşağıdaki gibi görünmek zorunda olmasıdır: CookieValueOne CookieValueTwo CookieValueThree Ve gibi değil: Çerez adı 'NewCookie' ayarlandı! Array ([0] => CookieValueOne [1] => CookieValueTwo [2] => CookieValueThree ) değer: Gerçi baskılı var Hala mutlu ! –

+0

@RickJellema Yanıtı çözülmüş olarak işaretleyin :) – mertizci

İlgili konular