1--TEST--
2Test asort() function : usage variations - sort strings
3--FILE--
4<?php
5/*
6 * testing asort() 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 asort() : 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 asort() by supplying various string arrays --\n";
32
33// loop through to test asort() 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(asort($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(asort($temp_array, $flag) ); // expecting : bool(true)
47    var_dump($temp_array);
48  }
49  $count++;
50}
51
52echo "Done\n";
53?>
54--EXPECT--
55*** Testing asort() : usage variations ***
56
57-- Testing asort() by supplying various string arrays --
58
59-- Iteration 1 --
60- With default sort_flag -
61bool(true)
62array(12) {
63  ["null"]=>
64  NULL
65  ["NULL"]=>
66  NULL
67  ["	"]=>
68  string(1) "	"
69  ["
70"]=>
71  string(1) "
72"
73  [""]=>
74  string(1) ""
75  [""]=>
76  string(1) ""
77  ["
77"]=>
78  string(1) "
78"
79  [""]=>
80  string(1) ""
81  ["\a"]=>
82  string(2) "\a"
83  ["\cx"]=>
84  string(3) "\cx"
85  ["\ddd"]=>
86  string(4) "\ddd"
87  ["\xhh"]=>
88  string(4) "\xhh"
89}
90- Sort_flag = SORT_REGULAR -
91bool(true)
92array(12) {
93  ["null"]=>
94  NULL
95  ["NULL"]=>
96  NULL
97  ["	"]=>
98  string(1) "	"
99  ["
100"]=>
101  string(1) "
102"
103  [""]=>
104  string(1) ""
105  [""]=>
106  string(1) ""
107  ["
107"]=>
108  string(1) "
108"
109  [""]=>
110  string(1) ""
111  ["\a"]=>
112  string(2) "\a"
113  ["\cx"]=>
114  string(3) "\cx"
115  ["\ddd"]=>
116  string(4) "\ddd"
117  ["\xhh"]=>
118  string(4) "\xhh"
119}
120- Sort_flag = SORT_STRING -
121bool(true)
122array(12) {
123  ["null"]=>
124  NULL
125  ["NULL"]=>
126  NULL
127  ["	"]=>
128  string(1) "	"
129  ["
130"]=>
131  string(1) "
132"
133  [""]=>
134  string(1) ""
135  [""]=>
136  string(1) ""
137  ["
137"]=>
138  string(1) "
138"
139  [""]=>
140  string(1) ""
141  ["\a"]=>
142  string(2) "\a"
143  ["\cx"]=>
144  string(3) "\cx"
145  ["\ddd"]=>
146  string(4) "\ddd"
147  ["\xhh"]=>
148  string(4) "\xhh"
149}
150
151-- Iteration 2 --
152- With default sort_flag -
153bool(true)
154array(12) {
155  ["B"]=>
156  string(6) "BANANA"
157  ["O"]=>
158  string(6) "Orange"
159  ["T"]=>
160  string(4) "TTTT"
161  ["Te"]=>
162  string(4) "Test"
163  ["X"]=>
164  string(1) "X"
165  ["a"]=>
166  string(5) "apple"
167  ["b"]=>
168  string(6) "banana"
169  ["l"]=>
170  string(5) "lemoN"
171  ["o"]=>
172  string(6) "oraNGe"
173  ["t"]=>
174  string(3) "ttt"
175  ["w"]=>
176  string(2) "ww"
177  ["x"]=>
178  string(1) "x"
179}
180- Sort_flag = SORT_REGULAR -
181bool(true)
182array(12) {
183  ["B"]=>
184  string(6) "BANANA"
185  ["O"]=>
186  string(6) "Orange"
187  ["T"]=>
188  string(4) "TTTT"
189  ["Te"]=>
190  string(4) "Test"
191  ["X"]=>
192  string(1) "X"
193  ["a"]=>
194  string(5) "apple"
195  ["b"]=>
196  string(6) "banana"
197  ["l"]=>
198  string(5) "lemoN"
199  ["o"]=>
200  string(6) "oraNGe"
201  ["t"]=>
202  string(3) "ttt"
203  ["w"]=>
204  string(2) "ww"
205  ["x"]=>
206  string(1) "x"
207}
208- Sort_flag = SORT_STRING -
209bool(true)
210array(12) {
211  ["B"]=>
212  string(6) "BANANA"
213  ["O"]=>
214  string(6) "Orange"
215  ["T"]=>
216  string(4) "TTTT"
217  ["Te"]=>
218  string(4) "Test"
219  ["X"]=>
220  string(1) "X"
221  ["a"]=>
222  string(5) "apple"
223  ["b"]=>
224  string(6) "banana"
225  ["l"]=>
226  string(5) "lemoN"
227  ["o"]=>
228  string(6) "oraNGe"
229  ["t"]=>
230  string(3) "ttt"
231  ["w"]=>
232  string(2) "ww"
233  ["x"]=>
234  string(1) "x"
235}
236Done
237