本文介紹了在 cookie 中存儲(chǔ) PHP 數(shù)組的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
在 cookie 中存儲(chǔ)數(shù)組的正確方法是什么?在 PHP 中代碼示例:
How is proper way to store an array in a cookie? in PHP Code example:
$number_ticket=2;
$info[7][5]=1;
$info[8][5]=1;
推薦答案
序列化數(shù)據(jù):
setcookie('cookie', serialize($info), time()+3600);
然后反序列化數(shù)據(jù):
$data = unserialize($_COOKIE['cookie'], ["allowed_classes" => false]);
data 之后,$info 和 $data 將具有相同的內(nèi)容.
After data, $info and $data will have the same content.
這篇關(guān)于在 cookie 中存儲(chǔ) PHP 數(shù)組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!