我有一个创建新会话的功能:
public function Create($data = array())
{
foreach($data as $name => $value)
{
return $_SESSION[$name] = $value;;
}
}
我正在使用以下示例:
Session::Create([
'_USER_ID' => $fetch_id,
'_USER_IP' => $_SERVER['REMOTE_ADDR'],
'_USER_AGENT' => $_SERVER['HTTP_USER_AGENT'],
'_USER_ACCEPT_LANGUAGE' => $_SERVER['HTTP_USER_ACCEPT_LANGUAGE'],
'_USER_ACCEPT_ENCODING' => $_SERVER['HTTP_USER_ACCEPT_ENCODING']
]);
这只创建一个会话“_USER_ID”,其他会话不存在。 哪里有问题?
var_dump: array(1) {["_USER_ID"]=> int(1)}
答案 0 :(得分:1)
return
(仅供参考:return
打破循环):
public function Create($data = array())
{
foreach($data as $name => $value)
{
$_SESSION[$name] = $value;;
}
return $_SESSION;
}