1--TEST--
2Test array_unshift() function : usage variations - double quoted strings for 'var' argument
3--FILE--
4<?php
5/*
6 * Testing the functionality of array_unshift() by passing different
7 * double quoted strings for $var argument that is prepended to the array
8 * passed through $array argument
9*/
10
11echo "*** Testing array_unshift() : double quoted strings for \$var argument ***\n";
12
13// array to be passed to $array argument
14$array = array('f' => "first", "s" => 'second', 1, 2.222);
15
16// different variations of double quoted strings to be passed to $var argument
17$vars = array (
18  "\$ -> This represents the dollar sign. hello dollar!!!",
19  "\t\r\v The quick brown fo\fx jumped over the lazy dog",
20  "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\\",
21  "hello world\\t",
22  "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t"
23);
24
25// loop through the various elements of $arrays to test array_unshift()
26$iterator = 1;
27foreach($vars as $var) {
28  echo "-- Iteration $iterator --\n";
29  $temp_array = $array;  // assign $array to another temporary $temp_array
30
31  /* with default argument */
32  // returns element count in the resulting array after arguments are pushed to
33  // beginning of the given array
34  var_dump( array_unshift($temp_array, $var) );
35
36// dump the resulting array
37  var_dump($temp_array);
38
39  /* with optional arguments */
40  // returns element count in the resulting array after arguments are pushed to
41  // beginning of the given array
42  $temp_array = $array;
43  var_dump( array_unshift($temp_array, $var, "hello", 'world') );
44
45  // dump the resulting array
46  var_dump($temp_array);
47  $iterator++;
48}
49
50echo "Done";
51?>
52--EXPECT--
53*** Testing array_unshift() : double quoted strings for $var argument ***
54-- Iteration 1 --
55int(5)
56array(5) {
57  [0]=>
58  string(53) "$ -> This represents the dollar sign. hello dollar!!!"
59  ["f"]=>
60  string(5) "first"
61  ["s"]=>
62  string(6) "second"
63  [1]=>
64  int(1)
65  [2]=>
66  float(2.222)
67}
68int(7)
69array(7) {
70  [0]=>
71  string(53) "$ -> This represents the dollar sign. hello dollar!!!"
72  [1]=>
73  string(5) "hello"
74  [2]=>
75  string(5) "world"
76  ["f"]=>
77  string(5) "first"
78  ["s"]=>
79  string(6) "second"
80  [3]=>
81  int(1)
82  [4]=>
83  float(2.222)
84}
85-- Iteration 2 --
86int(5)
87array(5) {
88  [0]=>
89  string(49) "
89 The quick brown fox jumped over the lazy dog"
90  ["f"]=>
91  string(5) "first"
92  ["s"]=>
93  string(6) "second"
94  [1]=>
95  int(1)
96  [2]=>
97  float(2.222)
98}
99int(7)
100array(7) {
101  [0]=>
102  string(49) "
102 The quick brown fox jumped over the lazy dog"
103  [1]=>
104  string(5) "hello"
105  [2]=>
106  string(5) "world"
107  ["f"]=>
108  string(5) "first"
109  ["s"]=>
110  string(6) "second"
111  [3]=>
112  int(1)
113  [4]=>
114  float(2.222)
115}
116-- Iteration 3 --
117int(5)
118array(5) {
119  [0]=>
120  string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\"
121  ["f"]=>
122  string(5) "first"
123  ["s"]=>
124  string(6) "second"
125  [1]=>
126  int(1)
127  [2]=>
128  float(2.222)
129}
130int(7)
131array(7) {
132  [0]=>
133  string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\"
134  [1]=>
135  string(5) "hello"
136  [2]=>
137  string(5) "world"
138  ["f"]=>
139  string(5) "first"
140  ["s"]=>
141  string(6) "second"
142  [3]=>
143  int(1)
144  [4]=>
145  float(2.222)
146}
147-- Iteration 4 --
148int(5)
149array(5) {
150  [0]=>
151  string(13) "hello world\t"
152  ["f"]=>
153  string(5) "first"
154  ["s"]=>
155  string(6) "second"
156  [1]=>
157  int(1)
158  [2]=>
159  float(2.222)
160}
161int(7)
162array(7) {
163  [0]=>
164  string(13) "hello world\t"
165  [1]=>
166  string(5) "hello"
167  [2]=>
168  string(5) "world"
169  ["f"]=>
170  string(5) "first"
171  ["s"]=>
172  string(6) "second"
173  [3]=>
174  int(1)
175  [4]=>
176  float(2.222)
177}
178-- Iteration 5 --
179int(5)
180array(5) {
181  [0]=>
182  string(70) "This is 	a text in bold letters
182\s\malong with slashes
183 : HELLO WORLD	"
184  ["f"]=>
185  string(5) "first"
186  ["s"]=>
187  string(6) "second"
188  [1]=>
189  int(1)
190  [2]=>
191  float(2.222)
192}
193int(7)
194array(7) {
195  [0]=>
196  string(70) "This is 	a text in bold letters
196\s\malong with slashes
197 : HELLO WORLD	"
198  [1]=>
199  string(5) "hello"
200  [2]=>
201  string(5) "world"
202  ["f"]=>
203  string(5) "first"
204  ["s"]=>
205  string(6) "second"
206  [3]=>
207  int(1)
208  [4]=>
209  float(2.222)
210}
211Done
212