在传递$_SESSION['var']
给函数时,如果$_SESSION['var']
未设置,我会收到通知:
Notice: Undefined index: var in scripname.php on line 49
有没有更安全的方法来获取,如果未设置$_SESSION['var']
,这会给我吗?0
$_SESSION['var']
先感谢您!!
在传递$_SESSION['var']
给函数时,如果$_SESSION['var']
未设置,我会收到通知:
Notice: Undefined index: var in scripname.php on line 49
有没有更安全的方法来获取,如果未设置$_SESSION['var']
,这会给我吗?0
$_SESSION['var']
先感谢您!!
$var = isset($_SESSION['var']) ? $_SESSION['var'] : 0
if (isset($_SESSION['var']))
{
echo "session is set";
}
else
{
echo "session is not set";
}
if (isset($_SESSION['var'])){
// Do something
}
if(!array_key_exists('var',$_SESSION))
{
$var = 0;
}
else
{
$var = $_SESSION['var'];
}
采用
if(isset($_SESSION['var']))
// do
怎么样:
$var = @$_SESSION['var'];