1--TEST--
2Test sprintf() function : usage variations - float formats with arrays
3--FILE--
4<?php
5/* Prototype  : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
6 * Description: Return a formatted string
7 * Source code: ext/standard/formatted_print.c
8*/
9
10echo "*** Testing sprintf() : float formats with arrays ***\n";
11
12// array of array types
13$array_values = array (
14  array(),
15  array(0),
16  array(1),
17  array(NULL),
18  array(null),
19  array("string"),
20  array(true),
21  array(TRUE),
22  array(false),
23  array(FALSE),
24  array(1,2,3,4),
25  array("123.456abc"),
26  array('123.456abc'),
27  array(1 => "One", "two" => 2)
28);
29
30// various float formats
31$float_formats = array(
32  "%f", "%hf", "%lf",
33  "%Lf", " %f", "%f ",
34  "\t%f", "\n%f", "%4f",
35  "%30f", "%[0-9]", "%*f"
36);
37
38$count = 1;
39foreach($array_values as $array_value) {
40  echo "\n-- Iteration $count --\n";
41
42  foreach($float_formats as $format) {
43    // with two arguments
44    var_dump( sprintf($format, $array_value) );
45  }
46  $count++;
47};
48
49echo "Done";
50?>
51--EXPECT--
52*** Testing sprintf() : float formats with arrays ***
53
54-- Iteration 1 --
55string(8) "0.000000"
56string(1) "f"
57string(8) "0.000000"
58string(1) "f"
59string(9) " 0.000000"
60string(9) "0.000000 "
61string(9) "	0.000000"
62string(9) "
630.000000"
64string(8) "0.000000"
65string(30) "                      0.000000"
66string(4) "0-9]"
67string(1) "f"
68
69-- Iteration 2 --
70string(8) "1.000000"
71string(1) "f"
72string(8) "1.000000"
73string(1) "f"
74string(9) " 1.000000"
75string(9) "1.000000 "
76string(9) "	1.000000"
77string(9) "
781.000000"
79string(8) "1.000000"
80string(30) "                      1.000000"
81string(4) "0-9]"
82string(1) "f"
83
84-- Iteration 3 --
85string(8) "1.000000"
86string(1) "f"
87string(8) "1.000000"
88string(1) "f"
89string(9) " 1.000000"
90string(9) "1.000000 "
91string(9) "	1.000000"
92string(9) "
931.000000"
94string(8) "1.000000"
95string(30) "                      1.000000"
96string(4) "0-9]"
97string(1) "f"
98
99-- Iteration 4 --
100string(8) "1.000000"
101string(1) "f"
102string(8) "1.000000"
103string(1) "f"
104string(9) " 1.000000"
105string(9) "1.000000 "
106string(9) "	1.000000"
107string(9) "
1081.000000"
109string(8) "1.000000"
110string(30) "                      1.000000"
111string(4) "0-9]"
112string(1) "f"
113
114-- Iteration 5 --
115string(8) "1.000000"
116string(1) "f"
117string(8) "1.000000"
118string(1) "f"
119string(9) " 1.000000"
120string(9) "1.000000 "
121string(9) "	1.000000"
122string(9) "
1231.000000"
124string(8) "1.000000"
125string(30) "                      1.000000"
126string(4) "0-9]"
127string(1) "f"
128
129-- Iteration 6 --
130string(8) "1.000000"
131string(1) "f"
132string(8) "1.000000"
133string(1) "f"
134string(9) " 1.000000"
135string(9) "1.000000 "
136string(9) "	1.000000"
137string(9) "
1381.000000"
139string(8) "1.000000"
140string(30) "                      1.000000"
141string(4) "0-9]"
142string(1) "f"
143
144-- Iteration 7 --
145string(8) "1.000000"
146string(1) "f"
147string(8) "1.000000"
148string(1) "f"
149string(9) " 1.000000"
150string(9) "1.000000 "
151string(9) "	1.000000"
152string(9) "
1531.000000"
154string(8) "1.000000"
155string(30) "                      1.000000"
156string(4) "0-9]"
157string(1) "f"
158
159-- Iteration 8 --
160string(8) "1.000000"
161string(1) "f"
162string(8) "1.000000"
163string(1) "f"
164string(9) " 1.000000"
165string(9) "1.000000 "
166string(9) "	1.000000"
167string(9) "
1681.000000"
169string(8) "1.000000"
170string(30) "                      1.000000"
171string(4) "0-9]"
172string(1) "f"
173
174-- Iteration 9 --
175string(8) "1.000000"
176string(1) "f"
177string(8) "1.000000"
178string(1) "f"
179string(9) " 1.000000"
180string(9) "1.000000 "
181string(9) "	1.000000"
182string(9) "
1831.000000"
184string(8) "1.000000"
185string(30) "                      1.000000"
186string(4) "0-9]"
187string(1) "f"
188
189-- Iteration 10 --
190string(8) "1.000000"
191string(1) "f"
192string(8) "1.000000"
193string(1) "f"
194string(9) " 1.000000"
195string(9) "1.000000 "
196string(9) "	1.000000"
197string(9) "
1981.000000"
199string(8) "1.000000"
200string(30) "                      1.000000"
201string(4) "0-9]"
202string(1) "f"
203
204-- Iteration 11 --
205string(8) "1.000000"
206string(1) "f"
207string(8) "1.000000"
208string(1) "f"
209string(9) " 1.000000"
210string(9) "1.000000 "
211string(9) "	1.000000"
212string(9) "
2131.000000"
214string(8) "1.000000"
215string(30) "                      1.000000"
216string(4) "0-9]"
217string(1) "f"
218
219-- Iteration 12 --
220string(8) "1.000000"
221string(1) "f"
222string(8) "1.000000"
223string(1) "f"
224string(9) " 1.000000"
225string(9) "1.000000 "
226string(9) "	1.000000"
227string(9) "
2281.000000"
229string(8) "1.000000"
230string(30) "                      1.000000"
231string(4) "0-9]"
232string(1) "f"
233
234-- Iteration 13 --
235string(8) "1.000000"
236string(1) "f"
237string(8) "1.000000"
238string(1) "f"
239string(9) " 1.000000"
240string(9) "1.000000 "
241string(9) "	1.000000"
242string(9) "
2431.000000"
244string(8) "1.000000"
245string(30) "                      1.000000"
246string(4) "0-9]"
247string(1) "f"
248
249-- Iteration 14 --
250string(8) "1.000000"
251string(1) "f"
252string(8) "1.000000"
253string(1) "f"
254string(9) " 1.000000"
255string(9) "1.000000 "
256string(9) "	1.000000"
257string(9) "
2581.000000"
259string(8) "1.000000"
260string(30) "                      1.000000"
261string(4) "0-9]"
262string(1) "f"
263Done
264