views:

49

answers:

4

Can i set session variables based on the variable input into the function. Such as:

function check($value){
$_SESSION['$value'];
//session checks
}
+2  A: 

Yes, but it would have to be $_SESSION[$value]. Single quoted strings are literal and do not have variable substitution (not that quotes are even needed in this case).

Daniel Egeberg
of course, I'm being a bit of a twit really
kalpaitch
+1  A: 

Just do:

$_SESSION[$value]
cletus
+2  A: 

usually you would use a key and a value, depends what you're trying to do i guess and what $value is

function check($value){
  $_SESSION[$value] = $value;
  //session checks
}
seengee
A: 

It is possible yes, but i would warn you to what the porpouse you want it for it might turn out to be an unusable thing.

<?php
session_start();

echo 'Welcome to the test';

$_SESSION['time']     = time();

echo '<br /><a href="test.php">Refresh Me (' . check('time') . ') </a>';

function check($value){
    return $_SESSION[$value];
}
?>
Prix