Another "tired of hunting for the exact syntax" things… Here's shorthand for an "if" statement:
echo isset($var) ? $var : "sorry, nothing here";
Another "tired of hunting for the exact syntax" things… Here's shorthand for an "if" statement:
echo isset($var) ? $var : "sorry, nothing here";
1 | Sunny
February 8th, 2007 at 12:22 pm
Also called a ternary operator. The outer parentheses can be dropped, too.
2 | Web Developer, James Radford
yup,
if(isset($var))
echo $var;
else
echo "sorry, nothing here";
can lead to problems if developers write immediately after the 'sorry, nothing here' message expecting it to be outside the conditional statement but otherwise this example can keep readability high whilst reducing the number of lines of code.
cheers,
James