세션배열하고 일반 배열이 일치하면?
본문
[cart] => Array ( [0] => Array ( [code] => 1543067730 [quantity] => Array ( [0] => 1 [1] => 1 ) [id] => Array ( [0] => 1 [1] => 2 ) ) )
일반 배열과 php 세션 배열이 일치하면 qty배열을 업데이트 하고싶은데요 코드 좀 봐주실분 있나요 ㅠㅠ
이게 좀 배열이 일치하기가 참 어렵네요 ㅠㅠ
if(!empty($quantity)) { foreach($_SESSION['cart'] as $k=> $value){ if(in_array($value['code'],$code)){ unset($_SESSION["cart"][$k]['quantity']); foreach ($quantity as $qty) { $_SESSION["cart"][$k]['quantity'] = $qty; } } } }
답변 1
print_r 된 것을 배열로 다시 돌리면
$_SESSION['cart'] = Array ( 'code' => 1543067730, 'quantity' => Array ( 1, 1 ), 'id' => Array ( 1, 2 ) ); 이렇게 되겠죠?
일단 $quantity, $code가 정의 되어 있지 않습니다.
아마도 일반배열에 속한 변수지 않을까 봅니다.
수정후 잘 실행될지는 모르겠고, 소스만 보자면 다음처럼 되어야지 합니다.
if(in_array($_SESSION["cart"]['code'], $code)){
unset($_SESSION["cart"]['quantity']);
foreach ($quantity as $qty) {
$_SESSION["cart"]['quantity'] = $qty;
}
답변을 작성하시기 전에 로그인 해주세요.