array_sum_variation6.phpt 839 B

123456789101112131415161718192021222324252627282930313233
  1. --TEST--
  2. Test array_sum() function : usage variations - associative array
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed array_sum(array $input)
  6. * Description: Returns the sum of the array entries
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Testing array_sum() with associative array as 'input' argument
  11. */
  12. echo "*** Testing array_sum() : with associative array ***\n";
  13. // array with numeric keys
  14. $input = array(0 => 1, 1 => 10, 2 => 0, 3 => -2, 4 => 23.56);
  15. echo "-- with numeric keys --\n";
  16. var_dump( array_sum($input) );
  17. // array with string keys
  18. $input = array('a' => 20, "b" => 50, 'c' => 0, 'd' => -30, "e" => 100);
  19. echo "-- with string keys --\n";
  20. var_dump( array_sum($input) );
  21. echo "Done"
  22. ?>
  23. --EXPECTF--
  24. *** Testing array_sum() : with associative array ***
  25. -- with numeric keys --
  26. float(32.56)
  27. -- with string keys --
  28. int(140)
  29. Done