1--TEST--
2Test arsort() function : usage variations - sort array with diff. sub arrays, 'sort_flags' as default/SORT_REGULAR
3--FILE--
4<?php
5/*
6 * testing arsort() by providing arrays contains sub arrays for $array argument with flowing flag values
7 * flag value as default
8 * SORT_REGULAR - compare items normally
9 * Note: arrays are sorted based on total count of elements inside it, when all the elements are arrays
10*/
11
12echo "*** Testing arsort() : usage variations ***\n";
13
14// array of arrays
15$various_arrays = array (
16  // null array
17  "array[0]" => array(),
18
19  // array contains null sub array
20  "array[1]" => array( "sub_array[1][0]" => array() ),
21
22  // array of arrays along with some values
23  "array[2]" => array("data[2,0]" => 44, "data[2,1]" => 11, "sub_array[2][0] " => array(64,61) ),
24
25  // array contains sub arrays
26  "array[3]" => array ( "sub_array[3][0]" => array(33,-5,6), "sub_array[3][1]" => array(11),
27                        "sub_array[3][2]" => array(22,-55), "sub_array[3][3]" => array() )
28);
29
30
31$count = 1;
32echo "\n-- Testing arsort() by supplying various arrays containing sub arrays --\n";
33
34// loop through to test arsort() with different arrays
35foreach ($various_arrays as $array) {
36
37  echo "\n-- Iteration $count --\n";
38  // testing arsort() function by supplying different arrays, flag value is default
39  echo "- With default sort_flag -\n";
40  $temp_array = $array;
41  var_dump(arsort($temp_array) );
42  var_dump($temp_array);
43
44  // testing arsort() function by supplying different arrays, flag value = SORT_REGULAR
45  echo "- Sort_flag = SORT_REGULAR -\n";
46  $temp_array = $array;
47  var_dump(arsort($temp_array, SORT_REGULAR) );
48  var_dump($temp_array);
49  $count++;
50}
51
52echo "Done\n";
53?>
54--EXPECT--
55*** Testing arsort() : usage variations ***
56
57-- Testing arsort() by supplying various arrays containing sub arrays --
58
59-- Iteration 1 --
60- With default sort_flag -
61bool(true)
62array(0) {
63}
64- Sort_flag = SORT_REGULAR -
65bool(true)
66array(0) {
67}
68
69-- Iteration 2 --
70- With default sort_flag -
71bool(true)
72array(1) {
73  ["sub_array[1][0]"]=>
74  array(0) {
75  }
76}
77- Sort_flag = SORT_REGULAR -
78bool(true)
79array(1) {
80  ["sub_array[1][0]"]=>
81  array(0) {
82  }
83}
84
85-- Iteration 3 --
86- With default sort_flag -
87bool(true)
88array(3) {
89  ["sub_array[2][0] "]=>
90  array(2) {
91    [0]=>
92    int(64)
93    [1]=>
94    int(61)
95  }
96  ["data[2,0]"]=>
97  int(44)
98  ["data[2,1]"]=>
99  int(11)
100}
101- Sort_flag = SORT_REGULAR -
102bool(true)
103array(3) {
104  ["sub_array[2][0] "]=>
105  array(2) {
106    [0]=>
107    int(64)
108    [1]=>
109    int(61)
110  }
111  ["data[2,0]"]=>
112  int(44)
113  ["data[2,1]"]=>
114  int(11)
115}
116
117-- Iteration 4 --
118- With default sort_flag -
119bool(true)
120array(4) {
121  ["sub_array[3][0]"]=>
122  array(3) {
123    [0]=>
124    int(33)
125    [1]=>
126    int(-5)
127    [2]=>
128    int(6)
129  }
130  ["sub_array[3][2]"]=>
131  array(2) {
132    [0]=>
133    int(22)
134    [1]=>
135    int(-55)
136  }
137  ["sub_array[3][1]"]=>
138  array(1) {
139    [0]=>
140    int(11)
141  }
142  ["sub_array[3][3]"]=>
143  array(0) {
144  }
145}
146- Sort_flag = SORT_REGULAR -
147bool(true)
148array(4) {
149  ["sub_array[3][0]"]=>
150  array(3) {
151    [0]=>
152    int(33)
153    [1]=>
154    int(-5)
155    [2]=>
156    int(6)
157  }
158  ["sub_array[3][2]"]=>
159  array(2) {
160    [0]=>
161    int(22)
162    [1]=>
163    int(-55)
164  }
165  ["sub_array[3][1]"]=>
166  array(1) {
167    [0]=>
168    int(11)
169  }
170  ["sub_array[3][3]"]=>
171  array(0) {
172  }
173}
174Done
175