Google News
logo
PHP Program to Modify a session variable
To modify a session variable in PHP, you can simply assign a new value to it. Here's an example :
Program :
<?php
// Start the session
session_start();

// Set a session variable
$_SESSION['color'] = 'blue';

// Modify the session variable
$_SESSION['color'] = 'red';

// Echo the modified session variable
echo $_SESSION['color'];  // Output: red
?>
Output :
red
In this example, we start a session using the `session_start()` function. We then set a session variable `color` to `'blue'`.

Next, we modify the `color` variable to `'red'` by simply assigning a new value to it. Finally, we echo the modified `color` variable, which outputs `'red'`.