justinh Posted January 22, 2009 Share Posted January 22, 2009 $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 More sharing options...
printf Posted January 22, 2009 Share Posted January 22, 2009 You will have to loop or use array_search because you have chosen to store items in the most illogical way! I tried to explain that to you yesterday. One of the objects of coding is to make things easier on your self, not harder. Link to comment https://forums.phpfreaks.com/topic/141955-arrays-in-sessions/#findComment-743299 Share on other sites More sharing options...
gevans Posted January 22, 2009 Share Posted January 22, 2009 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 More sharing options...
justinh Posted January 22, 2009 Author Share Posted January 22, 2009 I will have a look at your post again, but I was having a hard time understanding your approach. Yeah it works if I copy and paste it, but I really would like to understand how it is working. Link to comment https://forums.phpfreaks.com/topic/141955-arrays-in-sessions/#findComment-743307 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.