ID: 42567 Updated by: [EMAIL PROTECTED] Reported By: gustavoa at gmail dot com -Status: Open +Status: Feedback Bug Type: Session related Operating System: Windows PHP Version: 5.2.4 New Comment:
Please read: http://php.net/foreach There you find this: "As of PHP 5, you can easily modify array's elements by preceding $value with &." So this should work: foreach ($_SESSION as $key => &$value) { Previous Comments: ------------------------------------------------------------------------ [2007-09-05 15:39:53] gustavoa at gmail dot com Description: ------------ The following session is stored in my temp directory: old_var2|s:4:"foo2"; I try to iterate over the $_SESSION var (using foreach) to unset some session keys, in particular those who start with "old_" (see the attached code). But I can't. Besides, if after this iteration I try to modify the $_SESSION var nothing happens. I'm using IIS 5.1 (blame my boss). Reproduce code: --------------- session_start(); $prefix = 'old_'; foreach ($_SESSION as $key => $value) { if (substr($key, 0, 4) == $prefix) { unset($_SESSION[$key]); } } $_SESSION['var1'] = 'foo'; Expected result: ---------------- This change in the session file: var1|s:3:"foo"; Actual result: -------------- old_var2|s:4:"foo2"; ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42567&edit=1