Jump to content

if shorthand !!


asmith

Recommended Posts

Hey guys

 

This short hand syntax is killing me.

All I read about it on the net is about "echo" examples.

 

why this works  :

 

echo "content ",($something != 0)? "print!" : "", "continue ...";

 

but when i put it in a variable  :

 

$a =  "content ",($something != 0)? "print!" : "", "continue ...";

 

it gives me error?

 

How to solve it ?

any GREAT If shorthand tutorial?

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/125463-if-shorthand/
Share on other sites

you can nest it like this:

 

<?php
   $y = 10;
   $x = ($y < 11)? (($y < 11)? "yes" : "innerno") : "outterno"; 
   echo $x;
?>

 

output will be "yes", though seriously, I would not recommend doing this sort of thing.  You should never sacrifice readability for a couple less lines of code.

Link to comment
https://forums.phpfreaks.com/topic/125463-if-shorthand/#findComment-652308
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.