Unset all session variables with similar name
问题 I'm using some $_SESSION variables for filtering many query records that have a similar name (ex. $_SESSION['nameFilter'] or $_SESSION['cityFilter'] and so on). I'm using a link for resetting these filters, but I want to know if there is a way to unset all $_SESSION variables that have a name that is like: $_SESSION[(somewords)Filter] 回答1: Use foreach to enumerate the keys of $_SESSION[] , use substr() to get the last 6 characters of each key, use unset() to (what else?) unset it. As easy as: