Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

foreach($_SESSION AS $value){...} -> get array key of session

I fill a session like this:

$_SESSION[$id]=$value;

And I'm reading out the array with this:

foreach($_SESSION AS $value){...}

But how can I read out the $id of the session too? Array key?

Thanks!

like image 299
Roman Tisch Avatar asked Dec 02 '22 21:12

Roman Tisch


2 Answers

foreach($_SESSION as $key => $value){
}

http://br2.php.net/manual/en/control-structures.foreach.php

like image 136
Henrique Barcelos Avatar answered Dec 09 '22 15:12

Henrique Barcelos


You need something like the following:

foreach($_SESSION AS $key => $value) {
  echo "$key -> $value";
}
like image 44
Menztrual Avatar answered Dec 09 '22 15:12

Menztrual