Monthly Archives: October 2014

If else shortcut

The general format

(condition) ? (true return value) : (false return value)

Example

echo ‘Based on your score, you are a ‘,($score > 10 ? ‘genius’ : ‘nobody’);

References:

http://us2.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary

http://davidwalsh.name/php-shorthand-if-else-ternary-operators

Add days to a date

$adate = '2013-12-10'; //can use Ymd or mdY. Can't use dmY. Can use dash or slash to separate
$daystoadd = 7;
$newdate = date('Y-m-d',strtotime($adate) + (24*3600*$daystoadd)); //the date format is for output