is there a quicker way to do this?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
imananimeaddict
Forum Newbie
Posts: 9
Joined: Wed Mar 03, 2010 2:06 pm

is there a quicker way to do this?

Post 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;
}
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: is there a quicker way to do this?

Post 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']);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
imananimeaddict
Forum Newbie
Posts: 9
Joined: Wed Mar 03, 2010 2:06 pm

Re: is there a quicker way to do this?

Post by imananimeaddict »

thank you :)
Post Reply