我通过 php 序列化函数将数组转换为 cookie
$PromoteuserId='1';
$PromoteProductId='2';
$PromoteBrandId='3';
$PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
"PromoteProductId"=>$PromoteProductId,
"PromoteBrandId"=>$PromoteBrandId
);
$Promotedcart[] = $PromoteProductArray;
setcookie("Promotedcart", urlencode(serialize($Promotedcart)), time()+604800,'/');
Run Code Online (Sandbox Code Playgroud)
创建 cookie 后,我将使用反序列化 php 函数。
print_r(unserialize(urldecode($_COOKIE['Promotedcart'])));
Run Code Online (Sandbox Code Playgroud)
我需要更新 cookie 值。例如 - 我需要在 cookie 中搜索 PromotionProductId 值,如果那么它会将 cookie 值更新为与 PromotionProductId 一致。可以指导我如何更新该值吗?