1--TEST--
2Test sprintf() function : usage variations - int 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() : integer formats with arrays ***\n";
11
12// different arrays used to test the function
13$array_types = array (
14  array(),
15  array(0),
16  array(1),
17  array(-123),
18  array("123"),
19  array("-123"),
20  array(NULL),
21  array(null),
22  array("string"),
23  array(true),
24  array(TRUE),
25  array(false),
26  array(FALSE),
27  array(1,2,3,4),
28  array(1 => "One", "two" => 2)
29);
30
31// various integer formats
32$int_formats = array(
33  "%d", "%hd", "%ld",
34  "%Ld", " %d", "%d ",
35  "\t%d", "\n%d", "%4d",
36  "%30d", "%[0-9]", "%*d"
37);
38
39$count = 1;
40foreach($array_types as $arr) {
41  echo "\n-- Iteration $count --\n";
42
43  foreach($int_formats as $format) {
44    var_dump( sprintf($format, $arr) );
45  }
46  $count++;
47};
48
49echo "Done";
50?>
51--EXPECTF--
52*** Testing sprintf() : integer formats with arrays ***
53
54-- Iteration 1 --
55string(1) "0"
56string(1) "d"
57string(1) "0"
58string(1) "d"
59string(2) " 0"
60string(2) "0 "
61string(2) "	0"
62string(2) "
630"
64string(4) "   0"
65string(30) "                             0"
66string(4) "0-9]"
67string(1) "d"
68
69-- Iteration 2 --
70string(1) "1"
71string(1) "d"
72string(1) "1"
73string(1) "d"
74string(2) " 1"
75string(2) "1 "
76string(2) "	1"
77string(2) "
781"
79string(4) "   1"
80string(30) "                             1"
81string(4) "0-9]"
82string(1) "d"
83
84-- Iteration 3 --
85string(1) "1"
86string(1) "d"
87string(1) "1"
88string(1) "d"
89string(2) " 1"
90string(2) "1 "
91string(2) "	1"
92string(2) "
931"
94string(4) "   1"
95string(30) "                             1"
96string(4) "0-9]"
97string(1) "d"
98
99-- Iteration 4 --
100string(1) "1"
101string(1) "d"
102string(1) "1"
103string(1) "d"
104string(2) " 1"
105string(2) "1 "
106string(2) "	1"
107string(2) "
1081"
109string(4) "   1"
110string(30) "                             1"
111string(4) "0-9]"
112string(1) "d"
113
114-- Iteration 5 --
115string(1) "1"
116string(1) "d"
117string(1) "1"
118string(1) "d"
119string(2) " 1"
120string(2) "1 "
121string(2) "	1"
122string(2) "
1231"
124string(4) "   1"
125string(30) "                             1"
126string(4) "0-9]"
127string(1) "d"
128
129-- Iteration 6 --
130string(1) "1"
131string(1) "d"
132string(1) "1"
133string(1) "d"
134string(2) " 1"
135string(2) "1 "
136string(2) "	1"
137string(2) "
1381"
139string(4) "   1"
140string(30) "                             1"
141string(4) "0-9]"
142string(1) "d"
143
144-- Iteration 7 --
145string(1) "1"
146string(1) "d"
147string(1) "1"
148string(1) "d"
149string(2) " 1"
150string(2) "1 "
151string(2) "	1"
152string(2) "
1531"
154string(4) "   1"
155string(30) "                             1"
156string(4) "0-9]"
157string(1) "d"
158
159-- Iteration 8 --
160string(1) "1"
161string(1) "d"
162string(1) "1"
163string(1) "d"
164string(2) " 1"
165string(2) "1 "
166string(2) "	1"
167string(2) "
1681"
169string(4) "   1"
170string(30) "                             1"
171string(4) "0-9]"
172string(1) "d"
173
174-- Iteration 9 --
175string(1) "1"
176string(1) "d"
177string(1) "1"
178string(1) "d"
179string(2) " 1"
180string(2) "1 "
181string(2) "	1"
182string(2) "
1831"
184string(4) "   1"
185string(30) "                             1"
186string(4) "0-9]"
187string(1) "d"
188
189-- Iteration 10 --
190string(1) "1"
191string(1) "d"
192string(1) "1"
193string(1) "d"
194string(2) " 1"
195string(2) "1 "
196string(2) "	1"
197string(2) "
1981"
199string(4) "   1"
200string(30) "                             1"
201string(4) "0-9]"
202string(1) "d"
203
204-- Iteration 11 --
205string(1) "1"
206string(1) "d"
207string(1) "1"
208string(1) "d"
209string(2) " 1"
210string(2) "1 "
211string(2) "	1"
212string(2) "
2131"
214string(4) "   1"
215string(30) "                             1"
216string(4) "0-9]"
217string(1) "d"
218
219-- Iteration 12 --
220string(1) "1"
221string(1) "d"
222string(1) "1"
223string(1) "d"
224string(2) " 1"
225string(2) "1 "
226string(2) "	1"
227string(2) "
2281"
229string(4) "   1"
230string(30) "                             1"
231string(4) "0-9]"
232string(1) "d"
233
234-- Iteration 13 --
235string(1) "1"
236string(1) "d"
237string(1) "1"
238string(1) "d"
239string(2) " 1"
240string(2) "1 "
241string(2) "	1"
242string(2) "
2431"
244string(4) "   1"
245string(30) "                             1"
246string(4) "0-9]"
247string(1) "d"
248
249-- Iteration 14 --
250string(1) "1"
251string(1) "d"
252string(1) "1"
253string(1) "d"
254string(2) " 1"
255string(2) "1 "
256string(2) "	1"
257string(2) "
2581"
259string(4) "   1"
260string(30) "                             1"
261string(4) "0-9]"
262string(1) "d"
263
264-- Iteration 15 --
265string(1) "1"
266string(1) "d"
267string(1) "1"
268string(1) "d"
269string(2) " 1"
270string(2) "1 "
271string(2) "	1"
272string(2) "
2731"
274string(4) "   1"
275string(30) "                             1"
276string(4) "0-9]"
277string(1) "d"
278Done