Unset all session variables with similar name

后端 未结 4 810
生来不讨喜
生来不讨喜 2021-01-24 08:55

I\'m using some $_SESSION variables for filtering many query records that have a similar name (ex. $_SESSION[\'nameFilter\'] or $_SESSION[\'cityF

4条回答
  •  星月不相逢
    2021-01-24 09:48

    Steps :

    1.) Get all session variable using $_SESSION.
    2.) Check in every session key if it contain "Filter" string 
    then unset it using unset($_SESSION[(someword)Filter]);
    

    Try this :

    foreach($_SESSION as $key => $value){
      if (strstr($key, 'Filter') == 'Filter') {
        unset($_SESSION[$key]);
      }
    }
    

提交回复
热议问题