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