php check if variable exists and has value code example

Example 1: isset in php

$age = 0;
// Evaluates as true because $age is set
if (isset($age)) {
echo '$age is set even though it is empty';
}

Example 2: isset in php

//with new features in new PHP versions like 7
//you can simplify writing of isset in the following way,
//old way of isset to display name if name variable is not null
echo isset($name) ? $name : "no name"
 //new and simple way with null coalescing operator
echo $name ?? "no name"

Tags:

Php Example