12/26/2012

PHP ternary operator

There are some ternary operators in PHP language.

1. if ... else
   if($a==1){
     echo 'good';
   }
   else{
     echo 'error';
   }

   ==>
echo    ($a==1)? 'good': 'bad';

2. AND

   if($a==1) echo 'good';

  ==>
  ($a==1) AND  print( 'good';)

No comments:

Post a Comment