PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/2.0/Tests/Math/min.php

#
PHP | 33 lines | 23 code | 6 blank | 4 comment | 0 complexity | 6cebc2368352561d39d7c711da3d7a0d 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 min(2, 3, 1, 6, 7); // 1
  5. echo "\n";
  6. echo min(array(2, 4, 5)); // 2
  7. echo "\n";
  8. echo min(0, 'hello'); // 0
  9. echo "\n";
  10. echo min('hello', 0); // hello
  11. echo "\n";
  12. echo min('hello', -1); // -1
  13. echo "\n";
  14. function printme($a)
  15. {
  16. foreach ($a as $k => $v) echo "[$k] => $v\n";
  17. }
  18. // With multiple arrays, min compares from left to right
  19. // so in our example: 2 == 2, but 4 < 5
  20. $val = min(array(2, 4, 8), array(2, 5, 1)); // array(2, 4, 8)
  21. printme($val);
  22. echo "\n\n";
  23. // If both an array and non-array are given, the array
  24. // is never returned as it's considered the largest
  25. echo $val = min('string', array(2, 5, 7), 42); // string
  26. echo "\n\n";
  27. ?>