Skip to content

Instantly share code, notes, and snippets.

@MikSDigital
Created August 23, 2016 19:40
Show Gist options
  • Save MikSDigital/cbe8e2b5c5233bea0fdda162dfe76b08 to your computer and use it in GitHub Desktop.
Save MikSDigital/cbe8e2b5c5233bea0fdda162dfe76b08 to your computer and use it in GitHub Desktop.
examples of ternary operators
<?php
// #1, Larry Ullman, p.76
$q = 'SELECT UNIX_TIMESTAMP(MAX(date_added)), UNIX_TIMESTAMP(MAX(date_completed)) FROM tasks';
$r = mysqli_query($dbc,$q);
list($max_a,$max_c) = mysqli_fetch_array($r,MYSQLI_NUM);
$max = ($max_a > $max_c) ? $max_a : $max_c;
// #2, Bob Ray, p.285
$sortType = empty($sortType) ? 'NONE' : $sortType;
$delimeter = empty($delimeter) ? ',' : $delimeter;
// #3, Bob Ray, p.281
return $value == true ? 'Yes' : 'No';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment