Level 104
echo $variable ? 'YES' : '';
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Generally we can use ternary operator like this:
(Condition) ? (Statement1) : (Statement2);
But I want just one. For example:
if($variable)
{
echo "YES";
}
I want just the if condition in ternary.
Like this: $variable ? echo "YES";
But it's giving me error:
expected colon
Please or to participate in this conversation.