Solarpitch Posted November 16, 2007 Share Posted November 16, 2007 Hey, Heads melted working with arrays all day! I have this piece of code below that will store the user's favorites items on the site. It basically adds the item id to the session array. I just want to know how I can then list all the item id's from that session array to store in a variable? cheers if(isset($_GET['fav'])) { $_SESSION['favs'][] = $property_id; foreach($_SESSION['favs'] as $key=>$val) { } } // Here's how I can list them and print them to screen, but this is no good as each item id in the session array will need to be put into an sql query. So I need to individually pick each id out of the array. while (list(,$v) = each ($favs)) { echo $v } Link to comment https://forums.phpfreaks.com/topic/77549-solved-retreiving-array-from-a-session/ Share on other sites More sharing options...
teng84 Posted November 16, 2007 Share Posted November 16, 2007 <? $_SESSION['favs'][] ='teng1'; $_SESSION['favs'][] ='teng2'; $_SESSION['favs'][] ='teng3'; $_SESSION['favs'][] ='teng4'; $_SESSION['favs'][] ='teng5'; foreach($_SESSION['favs'] as $key=>$val){ echo "$"."_SESSION"."[favs][".$key ."]=".$val; echo '<br>'; } ?> see this sample Link to comment https://forums.phpfreaks.com/topic/77549-solved-retreiving-array-from-a-session/#findComment-392533 Share on other sites More sharing options...
Solarpitch Posted November 16, 2007 Author Share Posted November 16, 2007 Absolutely perfect! Now I can sleep early! Thanks man Link to comment https://forums.phpfreaks.com/topic/77549-solved-retreiving-array-from-a-session/#findComment-392539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.