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;
}
is there a quicker way to do this?
Moderator: General Moderators
-
imananimeaddict
- Forum Newbie
- Posts: 9
- Joined: Wed Mar 03, 2010 2:06 pm
- 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?
This is a little shorter:
Or if the order isn't important:
Code: Select all
$pointer = $_GET['q'];
unset($_SESSION['intin'][$pointer]);
$_SESSION['intin'] = array_values($_SESSION['intin']);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?
thank you 