noscrodamus noscrodamus - 6 months ago 9
PHP Question

What is this PHP command?

$userauthorized = empty($_SESSION['userauthorized']) ? 0 : $_SESSION['userauthorized'];


I'm sure this is an elementary question and googling this is a nightmare.

What does the " ? 0 : " mean?

Answer

It's called a ternary operator and it is essentially a short-hand if() statement.

You're basically saying:

if(empty($_SESSION['userauthorized'])) {
    $userauthorized =  0; 
} else {
    $userauthorized = $_SESSION['userauthorized'];
}
Comments