sycosyco123 Posted April 10, 2007 Share Posted April 10, 2007 I saw a syntax similar to this but the code below doent print anything. Is there an explanation of this syntax anywhere? <? $show1=1; ($show1==1?'show1':'show0'); $show1=0; ($show1==1?'show1':'show0'); ?> Link to comment https://forums.phpfreaks.com/topic/46493-syntax/ Share on other sites More sharing options...
per1os Posted April 10, 2007 Share Posted April 10, 2007 <?php $show1=1; ($show1==1)?'show1':'show0'; // if $show1 = 1 than print show1, else print show0 $show1=0; print ($show1==1)?'show1':'show0'; ?> SIMILIAR TO THIS: <?php $show1=1; if (!$show1 == 1) print 'show1'; else print 'show0'; ?> It is just an if/else statement written really short. I forget what they call it but is good for variable declarations etcc. Link to comment https://forums.phpfreaks.com/topic/46493-syntax/#findComment-226189 Share on other sites More sharing options...
utexas_pjm Posted April 10, 2007 Share Posted April 10, 2007 I forget what they call it but is good for variable declarations etcc. It's called the ternary operator. Link to comment https://forums.phpfreaks.com/topic/46493-syntax/#findComment-226212 Share on other sites More sharing options...
sycosyco123 Posted April 10, 2007 Author Share Posted April 10, 2007 That's great, thanks! Link to comment https://forums.phpfreaks.com/topic/46493-syntax/#findComment-226227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.