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