1--TEST--
2Test array_reverse() function : usage variations - assoc. array with diff. keys for 'array' argument
3--FILE--
4<?php
5/*
6 * Testing the functionality of array_reverse() by giving associative arrays with different
7 * keys for $array argument
8*/
9
10echo "*** Testing array_reverse() : usage variations ***\n";
11
12//get an unset variable
13$unset_var = 10;
14unset ($unset_var);
15
16//get a resource variable
17$fp = fopen(__FILE__, "r");
18
19//get a class
20class classA{
21  public function __toString(){
22    return "Class A object";
23  }
24}
25
26// get a heredoc string
27$heredoc = <<<EOT
28Hello world
29EOT;
30
31// initializing the array
32$arrays = array (
33
34       // empty array
35/*1*/  array(),
36
37       // arrays with integer keys
38       array(0 => "0"),
39       array(1 => "1"),
40       array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
41
42       // arrays with float keys
43/*5*/  array(2.3333 => "float"),
44       array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f3", 33333333.333333 => "f4"),
45
46       // arrays with string keys
47       array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33),
48/*8*/  array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33),
49       array("hello", $heredoc => "string"), // heredoc
50
51       // array with object, unset variable and resource variable
52       array(@$unset_var => "hello", $fp => 'resource'),
53
54       // array with mixed values
55/*11*/ array('hello' => 1, "fruit" => 2.2, $fp => 'resource', 133 => "int", 444.432 => "float", @$unset_var => "unset", $heredoc => "heredoc")
56);
57
58// loop through the various elements of $arrays to test array_reverse()
59$iterator = 1;
60foreach($arrays as $array) {
61  echo "-- Iteration $iterator --\n";
62  // with default argument
63  echo "- default argument -\n";
64  var_dump( array_reverse($array) );
65  // with $preserve_keys argument
66  echo "- \$preserve keys = true -\n";
67  var_dump( array_reverse($array, true) );
68  echo "- \$preserve_keys = false -\n";
69  var_dump( array_reverse($array, false) );
70  $iterator++;
71};
72
73// close the file resource used
74fclose($fp);
75
76echo "Done";
77?>
78--EXPECTF--
79*** Testing array_reverse() : usage variations ***
80
81Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
82
83Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
84-- Iteration 1 --
85- default argument -
86array(0) {
87}
88- $preserve keys = true -
89array(0) {
90}
91- $preserve_keys = false -
92array(0) {
93}
94-- Iteration 2 --
95- default argument -
96array(1) {
97  [0]=>
98  string(1) "0"
99}
100- $preserve keys = true -
101array(1) {
102  [0]=>
103  string(1) "0"
104}
105- $preserve_keys = false -
106array(1) {
107  [0]=>
108  string(1) "0"
109}
110-- Iteration 3 --
111- default argument -
112array(1) {
113  [0]=>
114  string(1) "1"
115}
116- $preserve keys = true -
117array(1) {
118  [1]=>
119  string(1) "1"
120}
121- $preserve_keys = false -
122array(1) {
123  [0]=>
124  string(1) "1"
125}
126-- Iteration 4 --
127- default argument -
128array(4) {
129  [0]=>
130  string(1) "4"
131  [1]=>
132  string(1) "3"
133  [2]=>
134  string(1) "2"
135  [3]=>
136  string(1) "1"
137}
138- $preserve keys = true -
139array(4) {
140  [4]=>
141  string(1) "4"
142  [3]=>
143  string(1) "3"
144  [2]=>
145  string(1) "2"
146  [1]=>
147  string(1) "1"
148}
149- $preserve_keys = false -
150array(4) {
151  [0]=>
152  string(1) "4"
153  [1]=>
154  string(1) "3"
155  [2]=>
156  string(1) "2"
157  [3]=>
158  string(1) "1"
159}
160-- Iteration 5 --
161- default argument -
162array(1) {
163  [0]=>
164  string(5) "float"
165}
166- $preserve keys = true -
167array(1) {
168  [2]=>
169  string(5) "float"
170}
171- $preserve_keys = false -
172array(1) {
173  [0]=>
174  string(5) "float"
175}
176-- Iteration 6 --
177- default argument -
178array(4) {
179  [0]=>
180  string(2) "f4"
181  [1]=>
182  string(2) "f3"
183  [2]=>
184  string(2) "f2"
185  [3]=>
186  string(2) "f1"
187}
188- $preserve keys = true -
189array(4) {
190  [33333333]=>
191  string(2) "f4"
192  [4]=>
193  string(2) "f3"
194  [3]=>
195  string(2) "f2"
196  [1]=>
197  string(2) "f1"
198}
199- $preserve_keys = false -
200array(4) {
201  [0]=>
202  string(2) "f4"
203  [1]=>
204  string(2) "f3"
205  [2]=>
206  string(2) "f2"
207  [3]=>
208  string(2) "f1"
209}
210-- Iteration 7 --
211- default argument -
212array(4) {
213  ["pen
214"]=>
215  int(33)
216  ["world"]=>
217  float(2.2)
218  ["re	d"]=>
219  string(5) "color"
220  ["	Hello"]=>
221  int(111)
222}
223- $preserve keys = true -
224array(4) {
225  ["pen
226"]=>
227  int(33)
228  ["world"]=>
229  float(2.2)
230  ["re	d"]=>
231  string(5) "color"
232  ["	Hello"]=>
233  int(111)
234}
235- $preserve_keys = false -
236array(4) {
237  ["pen
238"]=>
239  int(33)
240  ["world"]=>
241  float(2.2)
242  ["re	d"]=>
243  string(5) "color"
244  ["	Hello"]=>
245  int(111)
246}
247-- Iteration 8 --
248- default argument -
249array(4) {
250  ["pen
251"]=>
252  int(33)
253  ["world"]=>
254  float(2.2)
255  ["re	d"]=>
256  string(5) "color"
257  ["	Hello"]=>
258  int(111)
259}
260- $preserve keys = true -
261array(4) {
262  ["pen
263"]=>
264  int(33)
265  ["world"]=>
266  float(2.2)
267  ["re	d"]=>
268  string(5) "color"
269  ["	Hello"]=>
270  int(111)
271}
272- $preserve_keys = false -
273array(4) {
274  ["pen
275"]=>
276  int(33)
277  ["world"]=>
278  float(2.2)
279  ["re	d"]=>
280  string(5) "color"
281  ["	Hello"]=>
282  int(111)
283}
284-- Iteration 9 --
285- default argument -
286array(2) {
287  ["Hello world"]=>
288  string(6) "string"
289  [0]=>
290  string(5) "hello"
291}
292- $preserve keys = true -
293array(2) {
294  ["Hello world"]=>
295  string(6) "string"
296  [0]=>
297  string(5) "hello"
298}
299- $preserve_keys = false -
300array(2) {
301  ["Hello world"]=>
302  string(6) "string"
303  [0]=>
304  string(5) "hello"
305}
306-- Iteration 10 --
307- default argument -
308array(2) {
309  [0]=>
310  string(8) "resource"
311  [""]=>
312  string(5) "hello"
313}
314- $preserve keys = true -
315array(2) {
316  [5]=>
317  string(8) "resource"
318  [""]=>
319  string(5) "hello"
320}
321- $preserve_keys = false -
322array(2) {
323  [0]=>
324  string(8) "resource"
325  [""]=>
326  string(5) "hello"
327}
328-- Iteration 11 --
329- default argument -
330array(7) {
331  ["Hello world"]=>
332  string(7) "heredoc"
333  [""]=>
334  string(5) "unset"
335  [0]=>
336  string(5) "float"
337  [1]=>
338  string(3) "int"
339  [2]=>
340  string(8) "resource"
341  ["fruit"]=>
342  float(2.2)
343  ["hello"]=>
344  int(1)
345}
346- $preserve keys = true -
347array(7) {
348  ["Hello world"]=>
349  string(7) "heredoc"
350  [""]=>
351  string(5) "unset"
352  [444]=>
353  string(5) "float"
354  [133]=>
355  string(3) "int"
356  [5]=>
357  string(8) "resource"
358  ["fruit"]=>
359  float(2.2)
360  ["hello"]=>
361  int(1)
362}
363- $preserve_keys = false -
364array(7) {
365  ["Hello world"]=>
366  string(7) "heredoc"
367  [""]=>
368  string(5) "unset"
369  [0]=>
370  string(5) "float"
371  [1]=>
372  string(3) "int"
373  [2]=>
374  string(8) "resource"
375  ["fruit"]=>
376  float(2.2)
377  ["hello"]=>
378  int(1)
379}
380Done
381