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
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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.