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