1--TEST--
2Test array_unshift() function : usage variations - heredoc strings for 'var' argument
3--FILE--
4<?php
5/* Prototype  : int array_unshift(array $array, mixed $var [, mixed ...])
6 * Description: Pushes elements onto the beginning of the array
7 * Source code: ext/standard/array.c
8*/
9
10/*
11 * Testing the functionality of array_unshift() by passing different
12 * heredoc strings for $var argument that is prepended to the array
13 * passed through $array argument
14*/
15
16echo "*** Testing array_unshift() : heredoc strings for \$var argument ***\n";
17
18// heredoc with empty value
19$empty_string = <<<EOT
20EOT;
21
22// heredoc with blank line
23$blank_line = <<<EOT
24
25
26EOT;
27
28// heredoc with multiline string
29$multiline_string = <<<EOT
30hello world
31The big brown fox jumped over;
32the lazy dog
33This is a double quoted string
34EOT;
35
36// heredoc with different whitespaces
37$diff_whitespaces = <<<EOT
38hello\r world\t
391111\t\t != 2222\v\v
40heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
41EOT;
42
43// heredoc with numeric values
44$numeric_string = <<<EOT
4511 < 12. 123 >22
462222 != 1111.\t 0000 = 0000\n
47EOT;
48
49// heredoc with quote chars & slash
50$quote_char_string = <<<EOT
51This's a string with quotes:
52"strings in double quote";
53'strings in single quote';
54this\line is single quoted /with\slashes
55EOT;
56
57// array to be passed to $array argument
58$array = array('f' => "first", "s" => 'second', 1, 2.222);
59
60// different heredoc strings to be passed to $var argument
61$vars = array(
62  $empty_string,
63  $blank_line,
64  $multiline_string,
65  $diff_whitespaces,
66  $numeric_string,
67  $quote_char_string
68);
69
70// loop through the various elements of $arrays to test array_unshift()
71$iterator = 1;
72foreach($vars as $var) {
73  echo "-- Iteration $iterator --\n";
74  $temp_array = $array;  // assign $array to another temporary $temp_array
75
76  /* with default argument */
77  // returns element count in the resulting array after arguments are pushed to
78  // beginning of the given array
79  var_dump( array_unshift($temp_array, $var) );
80
81  // dump the resulting array
82  var_dump($temp_array);
83
84  /* with all possible arguments */
85  // returns element count in the resulting array after arguments are pushed to
86  // beginning of the given array
87  $temp_array = $array;
88  var_dump( array_unshift($temp_array, $var, "hello", 'world') );
89
90  // dump the resulting array
91  var_dump($temp_array);
92  $iterator++;
93}
94
95echo "Done";
96?>
97--EXPECTF--
98*** Testing array_unshift() : heredoc strings for $var argument ***
99-- Iteration 1 --
100int(5)
101array(5) {
102  [0]=>
103  string(0) ""
104  ["f"]=>
105  string(5) "first"
106  ["s"]=>
107  string(6) "second"
108  [1]=>
109  int(1)
110  [2]=>
111  float(2.222)
112}
113int(7)
114array(7) {
115  [0]=>
116  string(0) ""
117  [1]=>
118  string(5) "hello"
119  [2]=>
120  string(5) "world"
121  ["f"]=>
122  string(5) "first"
123  ["s"]=>
124  string(6) "second"
125  [3]=>
126  int(1)
127  [4]=>
128  float(2.222)
129}
130-- Iteration 2 --
131int(5)
132array(5) {
133  [0]=>
134  string(1) "
135"
136  ["f"]=>
137  string(5) "first"
138  ["s"]=>
139  string(6) "second"
140  [1]=>
141  int(1)
142  [2]=>
143  float(2.222)
144}
145int(7)
146array(7) {
147  [0]=>
148  string(1) "
149"
150  [1]=>
151  string(5) "hello"
152  [2]=>
153  string(5) "world"
154  ["f"]=>
155  string(5) "first"
156  ["s"]=>
157  string(6) "second"
158  [3]=>
159  int(1)
160  [4]=>
161  float(2.222)
162}
163-- Iteration 3 --
164int(5)
165array(5) {
166  [0]=>
167  string(86) "hello world
168The big brown fox jumped over;
169the lazy dog
170This is a double quoted string"
171  ["f"]=>
172  string(5) "first"
173  ["s"]=>
174  string(6) "second"
175  [1]=>
176  int(1)
177  [2]=>
178  float(2.222)
179}
180int(7)
181array(7) {
182  [0]=>
183  string(86) "hello world
184The big brown fox jumped over;
185the lazy dog
186This is a double quoted string"
187  [1]=>
188  string(5) "hello"
189  [2]=>
190  string(5) "world"
191  ["f"]=>
192  string(5) "first"
193  ["s"]=>
194  string(6) "second"
195  [3]=>
196  int(1)
197  [4]=>
198  float(2.222)
199}
200-- Iteration 4 --
201int(5)
202array(5) {
203  [0]=>
204  string(88) "hello
204 world
2051111		 != 2222
206heredoc
207double quoted string. withdifferentwhitespaces"
208  ["f"]=>
209  string(5) "first"
210  ["s"]=>
211  string(6) "second"
212  [1]=>
213  int(1)
214  [2]=>
215  float(2.222)
216}
217int(7)
218array(7) {
219  [0]=>
220  string(88) "hello
220 world
2211111		 != 2222
222heredoc
223double quoted string. withdifferentwhitespaces"
224  [1]=>
225  string(5) "hello"
226  [2]=>
227  string(5) "world"
228  ["f"]=>
229  string(5) "first"
230  ["s"]=>
231  string(6) "second"
232  [3]=>
233  int(1)
234  [4]=>
235  float(2.222)
236}
237-- Iteration 5 --
238int(5)
239array(5) {
240  [0]=>
241  string(44) "11 < 12. 123 >22
2422222 != 1111.	 0000 = 0000
243"
244  ["f"]=>
245  string(5) "first"
246  ["s"]=>
247  string(6) "second"
248  [1]=>
249  int(1)
250  [2]=>
251  float(2.222)
252}
253int(7)
254array(7) {
255  [0]=>
256  string(44) "11 < 12. 123 >22
2572222 != 1111.	 0000 = 0000
258"
259  [1]=>
260  string(5) "hello"
261  [2]=>
262  string(5) "world"
263  ["f"]=>
264  string(5) "first"
265  ["s"]=>
266  string(6) "second"
267  [3]=>
268  int(1)
269  [4]=>
270  float(2.222)
271}
272-- Iteration 6 --
273int(5)
274array(5) {
275  [0]=>
276  string(123) "This's a string with quotes:
277"strings in double quote";
278'strings in single quote';
279this\line is single quoted /with\slashes"
280  ["f"]=>
281  string(5) "first"
282  ["s"]=>
283  string(6) "second"
284  [1]=>
285  int(1)
286  [2]=>
287  float(2.222)
288}
289int(7)
290array(7) {
291  [0]=>
292  string(123) "This's a string with quotes:
293"strings in double quote";
294'strings in single quote';
295this\line is single quoted /with\slashes"
296  [1]=>
297  string(5) "hello"
298  [2]=>
299  string(5) "world"
300  ["f"]=>
301  string(5) "first"
302  ["s"]=>
303  string(6) "second"
304  [3]=>
305  int(1)
306  [4]=>
307  float(2.222)
308}
309Done
310