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'); ?> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
sycosyco123 Posted April 10, 2007 Author Share Posted April 10, 2007 That's great, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.