1--TEST--
2Test sprintf() function : usage variations - unsigned formats with array values
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() : unsigned formats with array values ***\n";
11
12// array of array values
13$array_values = array(
14  array(),
15  array(0),
16  array(1),
17  array(-12345),
18  array(+12345),
19  array(NULL),
20  array(null),
21  array("string"),
22  array(true),
23  array(TRUE),
24  array(false),
25  array(FALSE),
26  array(1,2,3,4),
27  array(1 => "One", "two" => 2)
28);
29
30// array of unsigned formats
31$unsigned_formats = array(
32  "%u", "%hu", "%lu",
33  "%Lu", " %u", "%u ",
34  "\t%u", "\n%u", "%4u",
35   "%30u", "%[0-9]", "%*u"
36);
37
38$count = 1;
39foreach($array_values as $array_value) {
40  echo "\n-- Iteration $count --\n";
41
42  foreach($unsigned_formats as $format) {
43    var_dump( sprintf($format, $array_value) );
44  }
45  $count++;
46};
47
48echo "Done";
49?>
50--EXPECTF--
51*** Testing sprintf() : unsigned formats with array values ***
52
53-- Iteration 1 --
54string(1) "0"
55string(1) "u"
56string(1) "0"
57string(1) "u"
58string(2) " 0"
59string(2) "0 "
60string(2) "	0"
61string(2) "
620"
63string(4) "   0"
64string(30) "                             0"
65string(4) "0-9]"
66string(1) "u"
67
68-- Iteration 2 --
69string(1) "1"
70string(1) "u"
71string(1) "1"
72string(1) "u"
73string(2) " 1"
74string(2) "1 "
75string(2) "	1"
76string(2) "
771"
78string(4) "   1"
79string(30) "                             1"
80string(4) "0-9]"
81string(1) "u"
82
83-- Iteration 3 --
84string(1) "1"
85string(1) "u"
86string(1) "1"
87string(1) "u"
88string(2) " 1"
89string(2) "1 "
90string(2) "	1"
91string(2) "
921"
93string(4) "   1"
94string(30) "                             1"
95string(4) "0-9]"
96string(1) "u"
97
98-- Iteration 4 --
99string(1) "1"
100string(1) "u"
101string(1) "1"
102string(1) "u"
103string(2) " 1"
104string(2) "1 "
105string(2) "	1"
106string(2) "
1071"
108string(4) "   1"
109string(30) "                             1"
110string(4) "0-9]"
111string(1) "u"
112
113-- Iteration 5 --
114string(1) "1"
115string(1) "u"
116string(1) "1"
117string(1) "u"
118string(2) " 1"
119string(2) "1 "
120string(2) "	1"
121string(2) "
1221"
123string(4) "   1"
124string(30) "                             1"
125string(4) "0-9]"
126string(1) "u"
127
128-- Iteration 6 --
129string(1) "1"
130string(1) "u"
131string(1) "1"
132string(1) "u"
133string(2) " 1"
134string(2) "1 "
135string(2) "	1"
136string(2) "
1371"
138string(4) "   1"
139string(30) "                             1"
140string(4) "0-9]"
141string(1) "u"
142
143-- Iteration 7 --
144string(1) "1"
145string(1) "u"
146string(1) "1"
147string(1) "u"
148string(2) " 1"
149string(2) "1 "
150string(2) "	1"
151string(2) "
1521"
153string(4) "   1"
154string(30) "                             1"
155string(4) "0-9]"
156string(1) "u"
157
158-- Iteration 8 --
159string(1) "1"
160string(1) "u"
161string(1) "1"
162string(1) "u"
163string(2) " 1"
164string(2) "1 "
165string(2) "	1"
166string(2) "
1671"
168string(4) "   1"
169string(30) "                             1"
170string(4) "0-9]"
171string(1) "u"
172
173-- Iteration 9 --
174string(1) "1"
175string(1) "u"
176string(1) "1"
177string(1) "u"
178string(2) " 1"
179string(2) "1 "
180string(2) "	1"
181string(2) "
1821"
183string(4) "   1"
184string(30) "                             1"
185string(4) "0-9]"
186string(1) "u"
187
188-- Iteration 10 --
189string(1) "1"
190string(1) "u"
191string(1) "1"
192string(1) "u"
193string(2) " 1"
194string(2) "1 "
195string(2) "	1"
196string(2) "
1971"
198string(4) "   1"
199string(30) "                             1"
200string(4) "0-9]"
201string(1) "u"
202
203-- Iteration 11 --
204string(1) "1"
205string(1) "u"
206string(1) "1"
207string(1) "u"
208string(2) " 1"
209string(2) "1 "
210string(2) "	1"
211string(2) "
2121"
213string(4) "   1"
214string(30) "                             1"
215string(4) "0-9]"
216string(1) "u"
217
218-- Iteration 12 --
219string(1) "1"
220string(1) "u"
221string(1) "1"
222string(1) "u"
223string(2) " 1"
224string(2) "1 "
225string(2) "	1"
226string(2) "
2271"
228string(4) "   1"
229string(30) "                             1"
230string(4) "0-9]"
231string(1) "u"
232
233-- Iteration 13 --
234string(1) "1"
235string(1) "u"
236string(1) "1"
237string(1) "u"
238string(2) " 1"
239string(2) "1 "
240string(2) "	1"
241string(2) "
2421"
243string(4) "   1"
244string(30) "                             1"
245string(4) "0-9]"
246string(1) "u"
247
248-- Iteration 14 --
249string(1) "1"
250string(1) "u"
251string(1) "1"
252string(1) "u"
253string(2) " 1"
254string(2) "1 "
255string(2) "	1"
256string(2) "
2571"
258string(4) "   1"
259string(30) "                             1"
260string(4) "0-9]"
261string(1) "u"
262Done