1--TEST--
2Test sprintf() function : usage variations - char 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() : char 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(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(1 => "One", "two" => 2)
26);
27
28// array of char formats
29$char_formats = array(
30  "%c", "%hc", "%lc",
31  "%Lc", " %c", "%c ",
32  "\t%c", "\n%c", "%4c",
33  "%30c", "%[a-bA-B@#$&]", "%*c"
34);
35
36$count = 1;
37foreach($array_values as $array_value) {
38  echo "\n-- Iteration $count --\n";
39
40  foreach($char_formats as $format) {
41    var_dump( sprintf($format, $array_value) );
42  }
43  $count++;
44};
45
46echo "Done";
47?>
48--EXPECTF--
49*** Testing sprintf() : char formats with array values ***
50
51-- Iteration 1 --
52string(1) "�"
53string(1) "c"
54string(1) "�"
55string(1) "c"
56string(2) " �"
57string(2) "� "
58string(2) "	�"
59string(2) "
60�"
61string(1) "�"
62string(1) "�"
63string(11) "a-bA-B@#$&]"
64string(1) "c"
65
66-- Iteration 2 --
67string(1) ""
68string(1) "c"
69string(1) ""
70string(1) "c"
71string(2) " "
72string(2) " "
73string(2) "	"
74string(2) "
75"
76string(1) ""
77string(1) ""
78string(11) "a-bA-B@#$&]"
79string(1) "c"
80
81-- Iteration 3 --
82string(1) ""
83string(1) "c"
84string(1) ""
85string(1) "c"
86string(2) " "
87string(2) " "
88string(2) "	"
89string(2) "
90"
91string(1) ""
92string(1) ""
93string(11) "a-bA-B@#$&]"
94string(1) "c"
95
96-- Iteration 4 --
97string(1) ""
98string(1) "c"
99string(1) ""
100string(1) "c"
101string(2) " "
102string(2) " "
103string(2) "	"
104string(2) "
105"
106string(1) ""
107string(1) ""
108string(11) "a-bA-B@#$&]"
109string(1) "c"
110
111-- Iteration 5 --
112string(1) ""
113string(1) "c"
114string(1) ""
115string(1) "c"
116string(2) " "
117string(2) " "
118string(2) "	"
119string(2) "
120"
121string(1) ""
122string(1) ""
123string(11) "a-bA-B@#$&]"
124string(1) "c"
125
126-- Iteration 6 --
127string(1) ""
128string(1) "c"
129string(1) ""
130string(1) "c"
131string(2) " "
132string(2) " "
133string(2) "	"
134string(2) "
135"
136string(1) ""
137string(1) ""
138string(11) "a-bA-B@#$&]"
139string(1) "c"
140
141-- Iteration 7 --
142string(1) ""
143string(1) "c"
144string(1) ""
145string(1) "c"
146string(2) " "
147string(2) " "
148string(2) "	"
149string(2) "
150"
151string(1) ""
152string(1) ""
153string(11) "a-bA-B@#$&]"
154string(1) "c"
155
156-- Iteration 8 --
157string(1) ""
158string(1) "c"
159string(1) ""
160string(1) "c"
161string(2) " "
162string(2) " "
163string(2) "	"
164string(2) "
165"
166string(1) ""
167string(1) ""
168string(11) "a-bA-B@#$&]"
169string(1) "c"
170
171-- Iteration 9 --
172string(1) ""
173string(1) "c"
174string(1) ""
175string(1) "c"
176string(2) " "
177string(2) " "
178string(2) "	"
179string(2) "
180"
181string(1) ""
182string(1) ""
183string(11) "a-bA-B@#$&]"
184string(1) "c"
185
186-- Iteration 10 --
187string(1) ""
188string(1) "c"
189string(1) ""
190string(1) "c"
191string(2) " "
192string(2) " "
193string(2) "	"
194string(2) "
195"
196string(1) ""
197string(1) ""
198string(11) "a-bA-B@#$&]"
199string(1) "c"
200
201-- Iteration 11 --
202string(1) ""
203string(1) "c"
204string(1) ""
205string(1) "c"
206string(2) " "
207string(2) " "
208string(2) "	"
209string(2) "
210"
211string(1) ""
212string(1) ""
213string(11) "a-bA-B@#$&]"
214string(1) "c"
215
216-- Iteration 12 --
217string(1) ""
218string(1) "c"
219string(1) ""
220string(1) "c"
221string(2) " "
222string(2) " "
223string(2) "	"
224string(2) "
225"
226string(1) ""
227string(1) ""
228string(11) "a-bA-B@#$&]"
229string(1) "c"
230Done
231