Archive

Posts Tagged ‘PHP’

Using Ternary PHP Conditionals (short hand)

February 26th, 2009

Standard php conditional:

  1. if (date("G") < 12) {
  2. echo 'Good morning';
  3. } else {
  4. echo 'Good afternoon';
  5. }

Shorthand…

  1. $greeting = (date("G") < 12) ? 'Good morning' : 'Good afternoon';
  2. echo $greeting;

(http://www.addedbytes.com/php/ternary-conditionals/)

PHP