我有以下代码。
$getPoetry['poet'] = $_SESSION[$member]['filters']['newspaper'] = array(
'$in' => $allFollowing
);
$getPoetry['poet']
内部包含完整数组,而$_SESSION[$member]['filters']['newspaper']
则没有。
可能是什么问题?
当我打印数组$_SESSION[$member]
时,它是一个带有空数组的键
答案 0 :(得分:2)
试试这个
<?php
session_start();
// create an array
$my_array=array('cat', 'dog', 'mouse', 'bird', 'crocodile', 'wombat', 'koala', 'kangaroo');
// put the array in a session variable
$_SESSION['animals']=$my_array;
// a little message to say we have done it
echo 'Putting array into a session variable';
// loop through the session array with foreach
foreach($_SESSION['animals'] as $key=>$value)
{
// and print out the values
echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />';
}
?>
你的例子我给你使用过的变量赋予了一些价值
<?php
session_start();
$member = 'new';
$allFollowing = 'follower';
$getPoetry['poet'] = $_SESSION[$member]['filters']['newspaper'] = array('$in' => $allFollowing);
print_r($_SESSION[$member]['filters']['newspaper']);
print_r($getPoetry);
?>
@Yogesh Suthar案例他错过了密钥而0不应该在会话中第一次检查密钥
<?php
session_start();
$abcd = $_SESSION['test']['filters']['newspaper'] = array('test'=>"abcd");
print_r($_SESSION['test']['filters']['newspaper']);
print_r($abcd);
?>
答案 1 :(得分:0)
工作正常。我认为您尚未在页面顶部
启动会话session_start();
session_start();
$abcd = $_SESSION[0]['filters']['newspaper'] = array("abcd");
print_r($_SESSION[0]['filters']['newspaper']);
print_r($abcd);
输出如下
Array ( [0] => abcd ) Array ( [0] => abcd )