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