-5

Is this possible?

if ($_SESSION['variable'] = 'one' {
    $_SESSION['variable'] = 'car';
}

It doesn't seem to be working. Is this enough information?

George Cummins
  • 28,485
  • 8
  • 71
  • 90
Ghost Echo
  • 1,997
  • 4
  • 31
  • 46

4 Answers4

6

Yes you can overwrite variables, but your codes syntax is wrong, try:

if ($_SESSION['variable'] == 'one') {
    $_SESSION['variable'] = 'car';
}
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
0

there is a syntax error and also in if clause your are not checking you are assigning the value

session_start();
if ($_SESSION['variable'] == 'one') {
$_SESSION['variable'] = 'car';
}
M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
0

The reason it isn't working is due to your syntax errors.

Here's an example that might help you understand what's going on...

$_SESSION['variable'] = 'one';
// use == for comparison... = for variable assignment
if($_SESSION['variable'] == 'one'){
    // reassign
    $_SESSION['variable'] = 'car';
}

var_dump($_SESSION);

// array(1) { ["variable"]=> string(3) "car" }

Demo

brbcoding
  • 13,378
  • 2
  • 37
  • 51
0

There is a syntax error or probably a typo in your code Try this

if ($_SESSION['variable'] == 'one') {
    $_SESSION['variable'] = 'car';
}
user1790464
  • 544
  • 3
  • 3