fork(3) download
  1. <?php
  2.  
  3. $a = containsOnlyNull([null,null,null,null,null]);
  4. $b = containsOnlyNull([null,null,1,null,null]);
  5.  
  6. echo ($a ? "all nulls" : "not all nulls") . PHP_EOL;
  7. echo ($b ? "all nulls" : "not all nulls");
  8.  
  9. function containsOnlyNull($arr) {
  10. return array_reduce($arr, function($carry, $item) {
  11. return $carry += (is_null($item) ? 0 : 1);
  12. }, 0) > 0 ? false : true;
  13. }
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
all nulls
not all nulls