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