
Originally Posted by
runeveryday
all of you made me know a lot,thank you!
what is the use of "unset a particular session variable"?
Sometimes you may need to unset a particular session variable among few more rather than destroying the whole session. So at that time you may need the unset(). Also once again, be informed that the function unset() is not only for the session variables. It can be used for rest of the variables as well in PHP.
PHP Code:
session_start();
$_SESSION['var1'] = 'value1';
$_SESSION['var2'] = 'value2';
$_SESSION['var3'] = 'value3';
$_SESSION['var4'] = 'value4';
$_SESSION['var5'] = 'value5';
if($_GET['unset'] == '1'){
unset($_SESSION['var2'], $_SESSION['var3']);
}
This will unset the two session variables $_SESSION['var2'], $_SESSION['var3'] where as rest of the variables will be available with value for you.
Hope it is clear now.
Bookmarks