vprintf_variation17.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. --TEST--
  2. Test vsprintf() function : usage variations - scientific formats with scientific values
  3. --FILE--
  4. <?php
  5. /*
  6. * Test vprintf() when different scientific formats and scientific values
  7. * are passed to the '$format' and '$args' arguments of the function
  8. */
  9. echo "*** Testing vprintf() : scientific formats and scientific values ***\n";
  10. // defining array of scientific formats
  11. $formats = array(
  12. '%e %+e %-e',
  13. '%le %4e %-4e',
  14. '%10.4e %-10.4e %.4e',
  15. '%\'#20e %\'20e %\'$20e %\'_20e',
  16. '%3$e %4$e %1$e %2$e'
  17. );
  18. // Arrays of scientific values for the format defined in $format.
  19. // Each sub array contains scientific values which correspond to each format string in $format
  20. $args_array = array(
  21. array(0, 1e0, "10e2" ),
  22. array(2.2e2, 1000e-2, 1000e7),
  23. array(-22e12, 10e20, 1.2e2),
  24. array(1e1, +1e2, -1e3, "1e2_"),
  25. array(3e3, 4e3, 1e3, 2e3)
  26. );
  27. // looping to test vprintf() with different scientific formats from the above $format array
  28. // and with signed and other types of values from the above $args_array array
  29. $counter = 1;
  30. foreach($formats as $format) {
  31. echo "\n-- Iteration $counter --\n";
  32. $result = vprintf($format, $args_array[$counter-1]);
  33. echo "\n";
  34. var_dump($result);
  35. $counter++;
  36. }
  37. ?>
  38. --EXPECT--
  39. *** Testing vprintf() : scientific formats and scientific values ***
  40. -- Iteration 1 --
  41. 0.000000e+0 +1.000000e+0 1.000000e+3
  42. int(36)
  43. -- Iteration 2 --
  44. 2.200000e+2 1.000000e+1 1.000000e+10
  45. int(36)
  46. -- Iteration 3 --
  47. -2.2000e+13 1.0000e+21 1.2000e+2
  48. int(32)
  49. -- Iteration 4 --
  50. #########1.000000e+1 1.000000e+2 $$$$$$$$-1.000000e+3 _________1.000000e+2
  51. int(74)
  52. -- Iteration 5 --
  53. 1.000000e+3 2.000000e+3 3.000000e+3 4.000000e+3
  54. int(47)