Hey I'm new to php and codeigniter. I know codeigniter has an isset function. what does the following code mean? Can someone please help
<?php echo isset($error) ? $error : ''; ?>
Hey I'm new to php and codeigniter. I know codeigniter has an isset function. what does the following code mean? Can someone please help
<?php echo isset($error) ? $error : ''; ?>
isset is a php function, you can use it without CodeIgnitor, but it basically checks to see if the variable has been set yet.
$someVariable = 'This variable has been set';
var_dump(isset($someVariable)); // True
var_dump(isset($anotherVariable)); // False
the ?
and :
parts tell PHP what to do. It's called a ternary operator, and can be thought as as a short if
statement:
echo isset($someVariable) ? 'set' : 'not set';
is the same as:
if (isset($someVariable)) {
echo 'set';
} else {
echo 'not set';
}
http://php.net/manual/en/function.isset.php http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary