Jump to content

arrays in sessions


justinh

Recommended Posts

 
$item_to_add = "item3"; 

$_SESSION['items']=array( array(item1, 1),
                                    array(item2, 2));

 

How would I check to see if  $item_to_add is inside $_SESSION['items'].

 

Also I was wondering how I would add $item_to_add to the session array.

 

 

Thanks,

 

Justin

 

 

Link to comment
https://forums.phpfreaks.com/topic/141955-arrays-in-sessions/
Share on other sites

Well, you can add the itesm as follows;

 

<?php
$_SESSION['items'][] = 'item1';
$_SESSION['items'][] = 'item2';
$_SESSION['items'][] = 'item3';

 

to check that they are in the array do the following

 

<?php
var_dump($_SESSION['items']);

 

To print each option out properly use the following

<?php
foreach($_SESSION['items'] as $item){
echo $item.'<br />';
}

 

Items to add could just be another array in the session;

 

$_SESSION['items_to_add']

 

then follow the above examples

Link to comment
https://forums.phpfreaks.com/topic/141955-arrays-in-sessions/#findComment-743302
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.