array_reduce_variation1.phpt 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. Test array_reduce() function : variation
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed array_reduce(array input, mixed callback [, int initial])
  6. * Description: Iteratively reduce the array to a single value via the callback.
  7. * Source code: ext/standard/array.c
  8. * Alias to functions:
  9. */
  10. echo "*** Testing array_reduce() : variation ***\n";
  11. function oneArg($v) {
  12. return $v;
  13. }
  14. function threeArgs($v, $w, $x) {
  15. return $v + $w + $x;
  16. }
  17. $array = array(1);
  18. echo "\n--- Testing with a callback with too few parameters ---\n";
  19. var_dump(array_reduce($array, "oneArg", 2));
  20. echo "\n--- Testing with a callback with too many parameters ---\n";
  21. var_dump(array_reduce($array, "threeArgs", 2));
  22. ?>
  23. ===DONE===
  24. --EXPECTF--
  25. *** Testing array_reduce() : variation ***
  26. --- Testing with a callback with too few parameters ---
  27. int(2)
  28. --- Testing with a callback with too many parameters ---
  29. Warning: Missing argument 3 for threeArgs() in %sarray_reduce_variation1.php on line %d
  30. Notice: Undefined variable: x in %sarray_reduce_variation1.php on line %d
  31. int(3)
  32. ===DONE===