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