多维会话数组

时间:2012-02-27 07:43:52

标签: php session

session_1.php

<?php session_start();
$_SESSION[0]['uid'] = 1;
$_SESSION[0]['uname'] = "n1";

$_SESSION[1]['uid'] = 2;
$_SESSION[1]['uname'] = "n2";
//echo "<pre>"; print_r($_SESSION); echo "</pre>"; die;

header("location:session_2.php");
?>



session_2.php
<?php 
    session_start();
    echo "<pre>";print_r($_SESSION);echo "</pre>";
?>

一些我怎么不能在会话中获取存储的值。有人能说出原因吗?

2 个答案:

答案 0 :(得分:1)

根据http://dk.php.net/manual/en/reserved.variables.session.php检查评论,根级别的密钥必须是字符串。

答案 1 :(得分:0)

$ _根级别的SESSION键必须是有效的变量名。

希望它会有所帮助。

立即查看这些小改动: -

session_1.php

<?php session_start();
$_SESSION['v0']['uid'] = 1;
$_SESSION['v0']['uname'] = "n1";

$_SESSION['v1']['uid'] = 2;
$_SESSION['v1']['uname'] = "n2";


header("location:session_2.php");
?>



session_2.php
<?php 
    session_start();
    echo "<pre>";print_r($_SESSION);echo "</pre>";
?>