To IF or not to IF?
One of the most used and important things you can do in PHP is an “if” statement.
if (!$variable1) {
echo “variable1 is NOT set”;
} else {
echo “variable1 is SET”;
}
Your typical IF statement. But if all you’re going to do is use ECHO to write a short string as output, then there’s a shortcut that I don’t see enough these days in people’s source code.
echo (!$variable1) ? “variable1 is NOT set” : “variable1 is SET”;
You’ve just condensed an IF statement into a single line. Obviously there are times when you would use this and times when you shouldn’t. But if you’re simply outputting a one liner like me here in the example code, this code is your friend.