1

I have a session like this: $_SESSION['mycatalogue']['user']

When I unset, I do this: unset($_SESSION['mycatalogue'])

What I want to know is, are all of the following meant to do the same thing: unset($_SESSION['mycatalogue'])

unset($_SESSION['mycatalogue']['user'])

$_SESSION['mycatalogue']['user'] = ""

So when I am unsetting a session or assigning NULL to it, it still keeps the arrays in memory?

user1448031
  • 2,172
  • 11
  • 44
  • 89

2 Answers2

0

First you need to clear about session concept. Your session is this $_SESSION['mycatalogue']. ['user'] is a index in your session names as mycatalogue.

If you want to unset a particular index from your session then use like

 unset($_SESSION['mycatalogue']['user'])

It is as same as you unset an index of array.

 $_SESSION['mycatalogue']['user'] = ""

will not unset your index user in your session. It will just set it as empty.

unset($_SESSION['mycatalogue'])

will unset your all session named as mycatalogue.

session_destroy will unset your all data related to current session but not unset any global variable

Awais Qarni
  • 17,492
  • 24
  • 75
  • 137
-1

Unset will destroy a particular session variable whereas session_destroy() will destroy all the session data for that user.

It really depends on your application as to which one you should use. Just keep the above in mind.

unset($_SESSION['name']); // will delete just the name data

session_destroy(); // will delete ALL data associated with that user.
chirag ode
  • 950
  • 7
  • 15