PO/changeitemamount.php
<?php
$currentcookie = $_COOKIE["producten"];
$product = $_GET["product"];
$amount = $_GET["amount"];
$cookiearray = explode(", ", $currentcookie); //De volgende lines splitsen de string in een array om het gemakkelijker te kunnen bewerken
$cookiearray2 = array();
for($i = 0; $i < count($cookiearray); $i++){
array_push($cookiearray2, explode("_", $cookiearray[$i]));
}
$currentcookie = "";
for($i = 0; $i < count($cookiearray2); $i++){
if($cookiearray2[$i][0] == $product){
$cookiearray2[$i][1] = $amount; //Stelt het aantal in als het product gevonden is
}
$currentcookie .= $cookiearray2[$i][0] . "_" . $cookiearray2[$i][1]; //Opnieuw de string samenstellen
if(count($cookiearray) - 1 != $i){
$currentcookie .= ", ";
}
}
// echo $currentcookie;
setcookie("producten", $currentcookie, time() + 3600);
// if(isset($currentcookie) && strpos($currentcookie, $product) > -1){
// //echo strpos($currentcookie, $product);
// echo $newcookie;
// }
?>
Resultaat
Made by Thijs Aarnoudse