你可以看一下session的內(nèi)部實(shí)現(xiàn) /** * This method is required by the interface [[\ArrayAccess]]. * @param integer $offset the offset to set element * @param mixed $item the element value */ public function offsetSet($offset, $item) { ? ?$this->open(); ? ?$_SESSION[$offset] = $item; } 是利用?$_SESSION[$offset] = $item; 來(lái)實(shí)現(xiàn)$session['user'] 這種賦值方式的,
2017-07-12
你可以看一下session的內(nèi)部實(shí)現(xiàn)
/**
* This method is required by the interface [[\ArrayAccess]].
* @param integer $offset the offset to set element
* @param mixed $item the element value
*/
public function offsetSet($offset, $item)
{
? ?$this->open();
? ?$_SESSION[$offset] = $item;
}
是利用?$_SESSION[$offset] = $item; 來(lái)實(shí)現(xiàn)$session['user'] 這種賦值方式的,
$session['user'] = '**' 實(shí)際上最終是調(diào)用了 ?$session->offsetSet('user','**'); 這個(gè)接口方法,
所以直接$session['user'][] 或者?$session['user']['xxx'] 是會(huì)報(bào)錯(cuò)的,
二維數(shù)組你可以用 $session['user'] = array('1','2','3'); 賦值
2016-03-13
$session['user'][]=****