1--TEST--
2Test arsort() function : usage variations - sort mixed values, 'sort_flags' as default/SORT_REGULAR (OK to fail as result is unpredectable)
3--FILE--
4<?php
5/* Prototype  : bool arsort ( array &$array [, int $sort_flags] )
6 * Description: Sort an array and maintain index association.
7                Elements will be arranged from highest to lowest when this function has completed.
8 * Source code: ext/standard/array.c
9*/
10
11/*
12 * testing arsort() by providing mixed value array for $array argument with following flag values.
13 * 1.flag value as default
14 * 2.SORT_REGULAR - compare items normally
15*/
16
17echo "*** Testing arsort() : usage variations ***\n";
18
19// mixed value array with different key values
20$mixed_values = array (
21  "array1" => array(),
22  "array2" => array ( "sub_array[2,1]" => array(33,-5,6), "sub_array[2,2]" => array(11),
23                      "sub_array[2,3]" => array(22,-55), "sub_array[2,4]" => array()
24                    ),
25  4 => 4, "4" => "4", 4.01 => 4.01, "b" => "b", "5" => "5", -2 => -2, -2.01 => -2.01,
26  -2.98989 => -2.98989, "-.9" => "-.9", "True" => "True", "" =>  "", NULL => NULL,
27  "ab" => "ab", "abcd" => "abcd", 0.01 => 0.01, -0 => -0, '' => '' ,
28  "abcd\x00abcd\x00abcd" => "abcd\x00abcd\x00abcd", 0.001 => 0.001
29);
30
31echo "\n-- Testing arsort() by supplying mixed value array, 'flag' value is default --\n";
32$temp_array = $mixed_values;
33var_dump( arsort($temp_array) );
34var_dump($temp_array);
35
36echo "\n-- Testing arsort() by supplying mixed value array, 'flag' value is SORT_REGULAR --\n";
37$temp_array = $mixed_values;
38var_dump( arsort($temp_array, SORT_REGULAR) );
39var_dump($temp_array);
40
41echo "Done\n";
42?>
43--EXPECTF--
44*** Testing arsort() : usage variations ***
45
46-- Testing arsort() by supplying mixed value array, 'flag' value is default --
47bool(true)
48array(13) {
49  ["array2"]=>
50  array(4) {
51    ["sub_array[2,1]"]=>
52    array(3) {
53      [0]=>
54      int(33)
55      [1]=>
56      int(-5)
57      [2]=>
58      int(6)
59    }
60    ["sub_array[2,2]"]=>
61    array(1) {
62      [0]=>
63      int(11)
64    }
65    ["sub_array[2,3]"]=>
66    array(2) {
67      [0]=>
68      int(22)
69      [1]=>
70      int(-55)
71    }
72    ["sub_array[2,4]"]=>
73    array(0) {
74    }
75  }
76  ["array1"]=>
77  array(0) {
78  }
79  [4]=>
80  float(4.01)
81  [0]=>
82  float(0.001)
83  ["b"]=>
84  string(1) "b"
85  ["abcd�abcd�abcd"]=>
86  string(14) "abcd�abcd�abcd"
87  ["abcd"]=>
88  string(4) "abcd"
89  ["ab"]=>
90  string(2) "ab"
91  ["True"]=>
92  string(4) "True"
93  [5]=>
94  string(1) "5"
95  ["-.9"]=>
96  string(3) "-.9"
97  [""]=>
98  string(0) ""
99  [-2]=>
100  float(-2.98989)
101}
102
103-- Testing arsort() by supplying mixed value array, 'flag' value is SORT_REGULAR --
104bool(true)
105array(13) {
106  ["array2"]=>
107  array(4) {
108    ["sub_array[2,1]"]=>
109    array(3) {
110      [0]=>
111      int(33)
112      [1]=>
113      int(-5)
114      [2]=>
115      int(6)
116    }
117    ["sub_array[2,2]"]=>
118    array(1) {
119      [0]=>
120      int(11)
121    }
122    ["sub_array[2,3]"]=>
123    array(2) {
124      [0]=>
125      int(22)
126      [1]=>
127      int(-55)
128    }
129    ["sub_array[2,4]"]=>
130    array(0) {
131    }
132  }
133  ["array1"]=>
134  array(0) {
135  }
136  [4]=>
137  float(4.01)
138  [0]=>
139  float(0.001)
140  ["b"]=>
141  string(1) "b"
142  ["abcd�abcd�abcd"]=>
143  string(14) "abcd�abcd�abcd"
144  ["abcd"]=>
145  string(4) "abcd"
146  ["ab"]=>
147  string(2) "ab"
148  ["True"]=>
149  string(4) "True"
150  [5]=>
151  string(1) "5"
152  ["-.9"]=>
153  string(3) "-.9"
154  [""]=>
155  string(0) ""
156  [-2]=>
157  float(-2.98989)
158}
159Done
160