Jump to content

[SOLVED] Adding values to an array?


Solarpitch

Recommended Posts

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

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

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.

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.