i need to know how to:-
- set up a session array
- add items to the array
- remove items from array
- list items in array
i need to know how to:-
the first thing you need to do to set up sessions you need to start the sessions.
[php]session_start();[/php]
then you cand declare it.
[php]$my_array = array(‘red’, ‘blue’, ‘black’, ‘white’);
$_SESSION[‘colors’] = $my_array;[/php]
To output the sessions array you will need a foreach loop.
[php]foreach($_SESSION[‘colors’] as $key=>$value)
{
echo ‘Value of $_SESSION[’."’".$key."’".’] is ‘."’".$value."’".’’;
}[/php]
To unset the items from array you will need unset();
[php]unset($_SESSION[‘colors’][‘id’]);[/php]
you will get the id from the output or you can declare it in the array.
[php]array(‘id1’ => ‘white’, ‘id2’=>‘black’);[/php]and so on…