Created
August 23, 2016 19:40
-
-
Save MikSDigital/cbe8e2b5c5233bea0fdda162dfe76b08 to your computer and use it in GitHub Desktop.
examples of ternary operators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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