1--TEST--
2Test arsort() function : usage variations - sort strings
3--FILE--
4<?php
5/*
6 * testing arsort() by providing different string arrays for $array argument with following flag values
7 *  flag value as default
8 *  SORT_REGULAR - compare items normally
9 *  SORT_STRING  - compare items as strings
10*/
11
12echo "*** Testing arsort() : usage variations ***\n";
13
14$various_arrays = array (
15  // group of escape sequences
16  array ("null"=>  null, "NULL" => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e",
17        "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh",
18        "\ddd" => "\ddd", "\v" => "\v"
19        ),
20
21  // array contains combination of capital/small letters
22  array ('l' => "lemoN", 'O' => "Orange", 'b' => "banana", 'a' => "apple", 'Te' => "Test",
23        'T' => "TTTT", 't' => "ttt", 'w' => "ww", 'x' => "x", 'X' => "X", 'o' => "oraNGe",
24        'B' => "BANANA"
25        )
26);
27
28$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING);
29
30$count = 1;
31echo "\n-- Testing arsort() by supplying various string arrays --\n";
32
33// loop through to test arsort() with different arrays
34foreach ($various_arrays as $array) {
35  echo "\n-- Iteration $count --\n";
36
37  echo "- With default sort_flag -\n";
38  $temp_array = $array;
39  var_dump(arsort($temp_array) ); // expecting : bool(true)
40  var_dump($temp_array);
41
42  // loop through $flags array and setting all possible flag values
43  foreach($flags as $key => $flag){
44    echo "- Sort_flag = $key -\n";
45    $temp_array = $array;
46    var_dump(arsort($temp_array, $flag) ); // expecting : bool(true)
47    var_dump($temp_array);
48  }
49  $count++;
50}
51
52echo "Done\n";
53?>
54--EXPECT--
55*** Testing arsort() : usage variations ***
56
57-- Testing arsort() by supplying various string arrays --
58
59-- Iteration 1 --
60- With default sort_flag -
61bool(true)
62array(12) {
63  ["\xhh"]=>
64  string(4) "\xhh"
65  ["\ddd"]=>
66  string(4) "\ddd"
67  ["\cx"]=>
68  string(3) "\cx"
69  ["\a"]=>
70  string(2) "\a"
71  [""]=>
72  string(1) ""
73  ["
73"]=>
74  string(1) "
74"
75  [""]=>
76  string(1) ""
77  [""]=>
78  string(1) ""
79  ["
80"]=>
81  string(1) "
82"
83  ["	"]=>
84  string(1) "	"
85  ["null"]=>
86  NULL
87  ["NULL"]=>
88  NULL
89}
90- Sort_flag = SORT_REGULAR -
91bool(true)
92array(12) {
93  ["\xhh"]=>
94  string(4) "\xhh"
95  ["\ddd"]=>
96  string(4) "\ddd"
97  ["\cx"]=>
98  string(3) "\cx"
99  ["\a"]=>
100  string(2) "\a"
101  [""]=>
102  string(1) ""
103  ["
103"]=>
104  string(1) "
104"
105  [""]=>
106  string(1) ""
107  [""]=>
108  string(1) ""
109  ["
110"]=>
111  string(1) "
112"
113  ["	"]=>
114  string(1) "	"
115  ["null"]=>
116  NULL
117  ["NULL"]=>
118  NULL
119}
120- Sort_flag = SORT_STRING -
121bool(true)
122array(12) {
123  ["\xhh"]=>
124  string(4) "\xhh"
125  ["\ddd"]=>
126  string(4) "\ddd"
127  ["\cx"]=>
128  string(3) "\cx"
129  ["\a"]=>
130  string(2) "\a"
131  [""]=>
132  string(1) ""
133  ["
133"]=>
134  string(1) "
134"
135  [""]=>
136  string(1) ""
137  [""]=>
138  string(1) ""
139  ["
140"]=>
141  string(1) "
142"
143  ["	"]=>
144  string(1) "	"
145  ["null"]=>
146  NULL
147  ["NULL"]=>
148  NULL
149}
150
151-- Iteration 2 --
152- With default sort_flag -
153bool(true)
154array(12) {
155  ["x"]=>
156  string(1) "x"
157  ["w"]=>
158  string(2) "ww"
159  ["t"]=>
160  string(3) "ttt"
161  ["o"]=>
162  string(6) "oraNGe"
163  ["l"]=>
164  string(5) "lemoN"
165  ["b"]=>
166  string(6) "banana"
167  ["a"]=>
168  string(5) "apple"
169  ["X"]=>
170  string(1) "X"
171  ["Te"]=>
172  string(4) "Test"
173  ["T"]=>
174  string(4) "TTTT"
175  ["O"]=>
176  string(6) "Orange"
177  ["B"]=>
178  string(6) "BANANA"
179}
180- Sort_flag = SORT_REGULAR -
181bool(true)
182array(12) {
183  ["x"]=>
184  string(1) "x"
185  ["w"]=>
186  string(2) "ww"
187  ["t"]=>
188  string(3) "ttt"
189  ["o"]=>
190  string(6) "oraNGe"
191  ["l"]=>
192  string(5) "lemoN"
193  ["b"]=>
194  string(6) "banana"
195  ["a"]=>
196  string(5) "apple"
197  ["X"]=>
198  string(1) "X"
199  ["Te"]=>
200  string(4) "Test"
201  ["T"]=>
202  string(4) "TTTT"
203  ["O"]=>
204  string(6) "Orange"
205  ["B"]=>
206  string(6) "BANANA"
207}
208- Sort_flag = SORT_STRING -
209bool(true)
210array(12) {
211  ["x"]=>
212  string(1) "x"
213  ["w"]=>
214  string(2) "ww"
215  ["t"]=>
216  string(3) "ttt"
217  ["o"]=>
218  string(6) "oraNGe"
219  ["l"]=>
220  string(5) "lemoN"
221  ["b"]=>
222  string(6) "banana"
223  ["a"]=>
224  string(5) "apple"
225  ["X"]=>
226  string(1) "X"
227  ["Te"]=>
228  string(4) "Test"
229  ["T"]=>
230  string(4) "TTTT"
231  ["O"]=>
232  string(6) "Orange"
233  ["B"]=>
234  string(6) "BANANA"
235}
236Done
237