1--TEST--
2Test array_unshift() function : usage variations - single quoted strings for 'var' argument
3--FILE--
4<?php
5/*
6 * Testing the functionality of array_unshift() by passing different
7 * single quoted strings for $var argument that is prepended to the array
8 * passed through $array argument
9*/
10
11echo "*** Testing array_unshift() : single 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 single 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() : single quoted strings for $var argument ***
54-- Iteration 1 --
55int(5)
56array(5) {
57  [0]=>
58  string(54) "\$ -> 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(54) "\$ -> 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(53) "\t\r\v The quick brown fo\fx 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(53) "\t\r\v The quick brown fo\fx 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(56) "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(56) "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(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t"
183  ["f"]=>
184  string(5) "first"
185  ["s"]=>
186  string(6) "second"
187  [1]=>
188  int(1)
189  [2]=>
190  float(2.222)
191}
192int(7)
193array(7) {
194  [0]=>
195  string(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t"
196  [1]=>
197  string(5) "hello"
198  [2]=>
199  string(5) "world"
200  ["f"]=>
201  string(5) "first"
202  ["s"]=>
203  string(6) "second"
204  [3]=>
205  int(1)
206  [4]=>
207  float(2.222)
208}
209Done
210