What does this line of PHP code mean? That is, the question mark bit followed by true, colon, false?
return(isset($_SESSION['id'])) ? true : false;
What does this line of PHP code mean? That is, the question mark bit followed by true, colon, false?
return(isset($_SESSION['id'])) ? true : false;
It's a ternary operator.
It's simply short-hand for:
if (isset($_SESSION['id']))
return true;
else
return false;
This syntax is for Ternary operators in PHP
It runs like (Condition to evalute) ?( Return result if condition is true) : (return result if condition is false)
in your case return(isset($_SESSION['id'])) ? true : false;
if $_SESSION['id']
is set it will return true and if session is not set it will return false.
?
mark is equivalent for if statement while :
is for else
It is short form of if else
statement
link : http://davidwalsh.name/php-shorthand-if-else-ternary-operators
This is a ternary operator.short for
if(isset($_SESSION['id'])){
return true;
}else{ return false;}
However this is useless because isset() already returns true or false
? boolean-condition [action] : [action]
is the ternary conditional operator and is short for:
if ([condition]) { [action] } else { [action] }