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