Solarpitch Posted November 14, 2007 Share Posted November 14, 2007 Hey guys, In the below script I am trying to add the property_id to an array every time the page is loaded. So if fav is set, I want to add the is of that property to an array and hold that array in a session. This is wrong but its what I was trying... $property_id = $_GET['property_id']; if(isset($_GET['fav'])) { $faves = array ($fav); session_register('faves'); } Link to comment https://forums.phpfreaks.com/topic/77392-solved-adding-values-to-an-array/ Share on other sites More sharing options...
Daukan Posted November 14, 2007 Share Posted November 14, 2007 I'm not exactly sure what you are asking but this how you would make an array with a session var <?php $property_id = $_GET['property_id']; // makes a numerical keyed array called property_ids $_SESSION['property_ids'][] = $property_id; //uses the property id as the key $_SESSION[$property_id] = $favs; ?> BTW session_register is depreciated. Use use $_SESSION = $value; to set a session var Link to comment https://forums.phpfreaks.com/topic/77392-solved-adding-values-to-an-array/#findComment-391774 Share on other sites More sharing options...
Solarpitch Posted November 14, 2007 Author Share Posted November 14, 2007 Cheers for that. When the page reloads or evrytime fav is set with a new value, I want that value to be added to the array. So say the user reloaded the page while viewing different property.. and they all had id's 465, 36, 125, 14 .. I want each of these to be added to the array each time this happens. Then I can loop through the array and display all the user's favorites based on that id's. Link to comment https://forums.phpfreaks.com/topic/77392-solved-adding-values-to-an-array/#findComment-391780 Share on other sites More sharing options...
Daukan Posted November 14, 2007 Share Posted November 14, 2007 I didn't test it but it should work <?php $_SESSION['favs'][] = $property_id; foreach($_SESSION['favs'] as $key=>$val) { echo $val; } ?> Link to comment https://forums.phpfreaks.com/topic/77392-solved-adding-values-to-an-array/#findComment-391786 Share on other sites More sharing options...
Solarpitch Posted November 14, 2007 Author Share Posted November 14, 2007 Perfect. Thanks a mill! Link to comment https://forums.phpfreaks.com/topic/77392-solved-adding-values-to-an-array/#findComment-391788 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.