views:

227

answers:

1

Hi, i read somewhere before, there is another way to perform the if-else statement, the code should be similar to this:

<?php
  $var = "stackoverflow";
  // Here is the if-else
  if(strlen($var) > 1) ? echo "TRUE" : echo "FALSE";
?>

I could only remember something like this, but it doesn't work, anyone knows how to write this 1 line if-else statement in php??

+4  A: 
echo strlen($var) > 1 ? "TRUE" : "FALSE";

or

if (strlen($var) > 1) echo "TRUE"; else echo "FALSE";
John Kugelman
Cool. YEah, found it, the first one is the one i am looking for. Thanks
jingleboy99