PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/2.0/Tests/Math/max.php

#
PHP | 34 lines | 24 code | 6 blank | 4 comment | 0 complexity | 92d7434402488bc1c94f36166febfaa3 MD5 | raw file
Possible License(s): CPL-1.0, GPL-2.0, CC-BY-SA-3.0, MPL-2.0-no-copyleft-exception, Apache-2.0
  1. [expect php]
  2. [file]
  3. <?php
  4. echo max(1, 3, 5, 6, 7); // 7
  5. echo "\n";
  6. echo max(array(2, 4, 5)); // 5
  7. echo "\n";
  8. echo max(0, 'hello'); // 0
  9. echo "\n";
  10. echo max('hello', 0); // hello
  11. echo "\n";
  12. echo max(-1, 'hello'); // hello
  13. echo "\n";
  14. function printme($a)
  15. {
  16. foreach ($a as $k => $v) echo "[$k] => $v\n";
  17. }
  18. // With multiple arrays, max compares from left to right
  19. // so in our example: 2 == 2, but 4 < 5
  20. $val = max(array(2, 4, 8), array(2, 5, 7)); // array(2, 5, 7)
  21. printme($val);
  22. echo "\n\n";
  23. // If both an array and non-array are given, the array
  24. // is always returned as it's seen as the largest
  25. $val = max('string', array(2, 5, 7), 42); // array(2, 5, 7)
  26. printme($val);
  27. echo "\n\n";
  28. ?>