Получаю следующее:
[{"id":"195"},{"count":"1"},{"summa":"300"},{"size":"10x10"},{"color":"red"},{"comment":"коммент"}]
А нужно, чтобы было так:
[{"id":"195","count":"1","summa":"300","size":"10x10","color":"red","comment":"коммент"}]
Можете подсказать какая ошибка в foreach или json_decode?
function card(id,count,summa,size,color,comment,del){
booktemp = {
"id" : id,
"count" : count,
"summa" : summa,
"size" : size,
"color" : color,
"comment" : comment
};
$.post("/submit/basket.php", {
json: JSON.stringify(booktemp)
}, function( data ) {
alert(data);
});
}
$cookie = $_COOKIE['item'];
$json = $_POST['json'];
if(isset($cookie)){
$json = array_merge(json_decode($json, TRUE), json_decode($cookie, TRUE));
}else{
$json = json_decode($json, TRUE);
}
foreach ($json as $key => $value) {
$result[] = array($key => $value);
}
$json = json_encode($result,JSON_UNESCAPED_UNICODE);
setcookie("item", $json, time()+259200, '/');