Posted By

kendsnyder on 01/26/11


Tagged

default coalesce


Versions (?)

Find first truthy value


 / Published in: PHP
 

Can be used like SQL COALESCE, IFNULL or for defaulting if a value is falsy

  1. function firstTruthy(/*$value1, $value2, $valueN...*/) {
  2. $args = func_get_args();
  3. foreach ($args as $a) {
  4. if (!!$a) {
  5. return $a;
  6. }
  7. }
  8. return null;
  9. }

Report this snippet  

You need to login to post a comment.