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