foreach($ _ SESSION AS $ value){...} - >获取会话的数组键

时间:2013-09-12 12:19:45

标签: php arrays session

我填写了这样一个会话:

$_SESSION[$id]=$value;

我正在用这个读出数组:

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

但是我怎样才能读出会话的$id呢?数组键?

谢谢!

6 个答案:

答案 0 :(得分:5)

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

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

答案 1 :(得分:4)

您需要以下内容:

foreach($_SESSION AS $key => $value) {
  echo "$key -> $value";
}

答案 2 :(得分:3)

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

答案 3 :(得分:2)

foreach ($_SESSION as $key => $value) {
  print $key . '<br>';
  print $value;
}

答案 4 :(得分:2)

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

答案 5 :(得分:0)

$array = array();
/*$array = array(0 => "Value");*/
$array[0] = "Value";
$_SESSION["array"] = $array;
/*$_SESSION["array"][0]= "Value 2";*/
foreach($_SESSION["array"] as $key => $value){
  print $key;
  print $value;
}