Ever found your self diving into endless reams of code just to set a simple variable??
e.g:
<?php if( $arraycount > 1 ) { $result = 'yes'; } else { $result = 'no'; } ?>
How stupid is that? So many lines of code for just 1 variable?
The Quick if!
It works like this:
function/string ( first condition ) ? "value if true" : "value if false";
So for the above code, we can do this:
<?php $result = ( $arraycount > 1 ) ? "yes" : "no"; ?>
It does the exact same thing!!
Of course you can also do:
<?php echo ( $arraycount > 1 ) ? "yes" : "no"; ?>
Remember, you can EVEN do this:
echo 'Is arraycount greater than 1? '. ( $arraycount > 1 ) ? "yes" : "no";
And another example cuz im bored and theres nothing on TV.
echo (eregi("MSIE",getenv("HTTP_USER_AGENT"))) ? 'Your using IE!' : 'Your not using IE!';
Anything really, its a good way of keeping order in your code, sparing your fingers, and loading pages better!
Edited by Matthew., 22 April 2007 - 07:39 AM.