1--TEST--
2Test asort() function : usage variations - sort array with diff. sub arrays, 'sort_flags' as default/SORT_REGULAR
3--FILE--
4<?php
5/*
6 * testing asort() 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 asort() : 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 asort() by supplying various arrays containing sub arrays --\n";
33
34// loop through to test asort() with different arrays
35foreach ($various_arrays as $array) {
36
37  echo "\n-- Iteration $count --\n";
38  // testing asort() function by supplying different arrays, flag value is default
39  echo "- With default sort_flag -\n";
40  $temp_array = $array;
41  var_dump(asort($temp_array) );
42  var_dump($temp_array);
43
44  // testing asort() function by supplying different arrays, flag value = SORT_REGULAR
45  echo "- Sort_flag = SORT_REGULAR -\n";
46  $temp_array = $array;
47  var_dump(asort($temp_array, SORT_REGULAR) );
48  var_dump($temp_array);
49  $count++;
50}
51
52echo "Done\n";
53?>
54--EXPECT--
55*** Testing asort() : usage variations ***
56
57-- Testing asort() 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  ["data[2,1]"]=>
90  int(11)
91  ["data[2,0]"]=>
92  int(44)
93  ["sub_array[2][0] "]=>
94  array(2) {
95    [0]=>
96    int(64)
97    [1]=>
98    int(61)
99  }
100}
101- Sort_flag = SORT_REGULAR -
102bool(true)
103array(3) {
104  ["data[2,1]"]=>
105  int(11)
106  ["data[2,0]"]=>
107  int(44)
108  ["sub_array[2][0] "]=>
109  array(2) {
110    [0]=>
111    int(64)
112    [1]=>
113    int(61)
114  }
115}
116
117-- Iteration 4 --
118- With default sort_flag -
119bool(true)
120array(4) {
121  ["sub_array[3][3]"]=>
122  array(0) {
123  }
124  ["sub_array[3][1]"]=>
125  array(1) {
126    [0]=>
127    int(11)
128  }
129  ["sub_array[3][2]"]=>
130  array(2) {
131    [0]=>
132    int(22)
133    [1]=>
134    int(-55)
135  }
136  ["sub_array[3][0]"]=>
137  array(3) {
138    [0]=>
139    int(33)
140    [1]=>
141    int(-5)
142    [2]=>
143    int(6)
144  }
145}
146- Sort_flag = SORT_REGULAR -
147bool(true)
148array(4) {
149  ["sub_array[3][3]"]=>
150  array(0) {
151  }
152  ["sub_array[3][1]"]=>
153  array(1) {
154    [0]=>
155    int(11)
156  }
157  ["sub_array[3][2]"]=>
158  array(2) {
159    [0]=>
160    int(22)
161    [1]=>
162    int(-55)
163  }
164  ["sub_array[3][0]"]=>
165  array(3) {
166    [0]=>
167    int(33)
168    [1]=>
169    int(-5)
170    [2]=>
171    int(6)
172  }
173}
174Done
175