How do I echo the session name in a foreach loop in PHP?

echo, foreach, php, session

Solution

This?

foreach($_SESSION as $key => $value) {
    echo  'Current session variable ' . $key . ' is: ' . $value . '<br />';
}

Problem

I am looping through my session variables. I have been able to echo the session values, but I would also like to echo the session name that corresponds with that value. How do I echo out the session variable name each time it loops? This is the code I currently have: ``` foreach($_SESSION as $value) { echo 'Current session variable is: ' . $value . '<br />'; } ```

Original source