Ever found your self diving into endless reams of code just to set a simple variable??
e.g:
CODE
<?php
if( $arraycount > 1 )
{
$result = 'yes';
}
else
{
$result = 'no';
}
?>
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:
CODE
<?php
$result = ( $arraycount > 1 ) ? "yes" : "no";
?>
$result = ( $arraycount > 1 ) ? "yes" : "no";
?>
It does the exact same thing!!
Of course you can also do:
CODE
<?php
echo ( $arraycount > 1 ) ? "yes" : "no";
?>
echo ( $arraycount > 1 ) ? "yes" : "no";
?>
Remember, you can EVEN do this:
CODE
echo 'Is arraycount greater than 1? '. ( $arraycount > 1 ) ? "yes" : "no";
And another example cuz im bored and theres nothing on TV.
CODE
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!