Reputation: 3731
while passing $_SESSION['var']
to function, if $_SESSION['var']
is unset, I'm getting Notice:
Notice: Undefined index: var in scripname.php on line 49
Is there safer way to obtain $_SESSION['var']
, which will give me 0
if $_SESSION['var']
is unset?
Thank you in advance!!
Upvotes: 0
Views: 89
Reputation: 3484
if(!array_key_exists('var',$_SESSION))
{
$var = 0;
}
else
{
$var = $_SESSION['var'];
}
Upvotes: 0
Reputation: 4312
if (isset($_SESSION['var']))
{
echo "session is set";
}
else
{
echo "session is not set";
}
Upvotes: 3