Google News
logo
PHP Program to Get all session variable values
To get all session variable values, we can use the `$_SESSION` superglobal variable in PHP. Here's an example PHP program that demonstrates this :
Program :
<?php
// Start the session
session_start();

// Set some session variables
$_SESSION["name"] = "John";
$_SESSION["age"] = 30;

// Get all session variable values
$session_values = array_values($_SESSION);

// Output the session values
print_r($session_values);
?>
Output :
Array
(
    [0] => John
    [1] => 30
)
In this example, we start the session using `session_start()`, then set two session variables using the `$_SESSION` superglobal. We then use the `array_values()` function to get an array of all session variable values, and output the array using `print_r()`.

This shows that we have successfully retrieved all session variable values into an array.