Delete from array help

Posted by Camran on Stack Overflow See other posts from Stack Overflow or by Camran
Published on 2010-04-27T16:56:03Z Indexed on 2010/04/27 17:03 UTC
Read the original article Hit count: 293

Filed under:
|
|

I have a cookie which stores info in an array.

This is for a classifieds website, and whenever users delete their 'ads' the cookie must also be removed of the ad which was deleted.

So I have this:

if (isset($_COOKIE['watched_ads'])){
$expir = time()+1728000;
        $ad_arr = unserialize($_COOKIE['watched_ads']);
        foreach($ad_arr as $val){
            if($val==$id){  // $id is something like "bmw_m3_10141912"
                unset($val);
                            setcookie('watched_ads', serialize($ad_arr), $expir, '/');
            }
        }
        }

This doesn't work... any idea why? I think its a problem with the unset part... Also, keep in mind if there is only one value inside the array, what will happen then?

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about html