isset short way  [ 879 views ]

How we can check if variable is defined or if not than get a default value? The general answer is isset and ternary operator

$myVar = isset($_SESSION["variableName"]) ? $_SESSION["variableName"] : 'defaultValue';

let’s simplify this!

$myVar = isset($_SESSION["variableName"]) ?: 'defaultValue';

or after PHP 7.0.1 you can use this shorter way

$myVar = $_SESSION["variableName"] ?? 'defaultValue';
#sidebar a { color:#fff; } #sidebar ul ul li { color: #DEF585; } #sidebar h2 { color: #fff; } #sidebar ul p, #sidebar ul select { color: #BEDDBE; } #backfly { background: url(images/golfBallWallPaper.jpg) left bottom fixed repeat-x #65a51d; }