tags:

views:

52

answers:

2

is it correct to unset the session variable for a particular index as the vay whole session is made unset in PHP?

I know this works: unset($_SESSION['bannersize'])

But does this works ? : unset($_SESSION['bannersize'][3])

or is there any other way to unset any particular desired index of the session and then again rearrange the values inside it to remove the empty index..?

A: 

I know it is possible to unset a named key. ie you can unset arr['home']['manager']. But i am not very sure about arr['home'][1]. Probably that also should work.

Wind Chimez
+2  A: 

If you want to remove an array item and reindex the array, you can use array_splice to do so:

$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, 1);  // removes $input[1]
var_dump($input);
Gumbo
@Gumbo in my case the array whose item is to be removed is a session variable, so will it do in that case as well???
OM The Eternity
@OM session variables are regular variables in either way.
Col. Shrapnel
Orrite that must give the output the way i want...
OM The Eternity
@OM The Eternity: You just need to know the offset of the item you want to remove.
Gumbo