array_sum_variation3.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --TEST--
  2. Test array_sum() function : usage variations - array with different float values
  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. * sum of array containing different float values
  11. */
  12. echo "*** Testing array_sum() : array with different float values ***\n";
  13. // Simple float array
  14. $float_input = array( 1.1, 2.3, 0.0, 0.5, -2.3, -0.8, .5);
  15. echo "-- simple float array --\n";
  16. var_dump( array_sum($float_input) );
  17. // float array with scientific notations
  18. $float_input = array( 1.2e2, 23.4e3, -4.1e2, 0.2e2, 2.1e-2, .5e3);
  19. echo "-- float array with scientific notations e and E --\n";
  20. var_dump( array_sum($float_input) );
  21. $float_input = array( 1.2E2, 23.4E3, -4.1E2, 0.2E2, 2.1E-2, .5E3);
  22. var_dump( array_sum($float_input) );
  23. // Mixed float array
  24. $float_input = array(
  25. 1.2,
  26. 0.5
  27. -5.8,
  28. 6.334,
  29. -0.65,
  30. 1.2e3,
  31. -2.3e2,
  32. 5.56E3,
  33. -3.82E-2
  34. );
  35. echo "-- Mixed float array --\n";
  36. var_dump( array_sum($float_input) );
  37. echo "Done"
  38. ?>
  39. --EXPECTF--
  40. *** Testing array_sum() : array with different float values ***
  41. -- simple float array --
  42. float(1.3)
  43. -- float array with scientific notations e and E --
  44. float(23630.021)
  45. float(23630.021)
  46. -- Mixed float array --
  47. float(6531.5458)
  48. Done