Page 1 of 1

is there a quicker way to do this?

Posted: Wed Mar 03, 2010 2:13 pm
by imananimeaddict
Hello. i am making an itinerary option for my uni project

i have the following code to remove an element from the session's intin array.
because i need the session array's key to stay as 1,2,3,4 when an item is removed not 1,2,4 i have found that i had to save the array into a new array, clear the session[intin] then reassign it.

is there a better and faster way?!!? please help

$pointer=$_GET["q"];

unset($_SESSION['intin'][$pointer]);

$object=(array_values($_SESSION['intin']));

$_SESSION[intin]=array();

foreach($object as $key)
{
$_SESSION[intin]=$object;
}

Re: is there a quicker way to do this?

Posted: Wed Mar 03, 2010 2:26 pm
by AbraCadaver
This is a little shorter:

Code: Select all

$pointer = $_GET['q'];
unset($_SESSION['intin'][$pointer]);
$_SESSION['intin'] = array_values($_SESSION['intin']);
Or if the order isn't important:

Code: Select all

$pointer = $_GET['q'];
unset($_SESSION['intin'][$pointer]);
sort($_SESSION['intin']);
//or
shuffle($_SESSION['intin']);

Re: is there a quicker way to do this?

Posted: Wed Mar 03, 2010 7:04 pm
by imananimeaddict
thank you :)