1--TEST--
2Test krsort() 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 krsort ( array &$array [, int $sort_flags] )
6 * Description: Sort an array by key in reverse order, maintaining key to data correlation.
7 * Source code: ext/standard/array.c
8*/
9
10/*
11 * testing krsort() by providing array of mixed values for $array argument
12 * with following flag  values:
13 *  1.flag value as defualt
14 *  2.SORT_REGULAR - compare items normally
15*/
16
17echo "*** Testing krsort() : 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 krsort() by supplying mixed value array, 'flag' value is defualt --\n";
32$temp_array = $mixed_values;
33var_dump( krsort($temp_array) );
34var_dump($temp_array);
35
36echo "\n-- Testing krsort() by supplying mixed value array, 'flag' value is SORT_REGULAR --\n";
37$temp_array = $mixed_values;
38var_dump( krsort($temp_array, SORT_REGULAR) );
39var_dump($temp_array);
40
41echo "Done\n";
42?>
43--EXPECTF--
44*** Testing krsort() : usage variations ***
45
46-- Testing krsort() by supplying mixed value array, 'flag' value is defualt --
47bool(true)
48array(13) {
49  [5]=>
50  string(1) "5"
51  [4]=>
52  float(4.01)
53  ["b"]=>
54  string(1) "b"
55  ["array2"]=>
56  array(4) {
57    ["sub_array[2,1]"]=>
58    array(3) {
59      [0]=>
60      int(33)
61      [1]=>
62      int(-5)
63      [2]=>
64      int(6)
65    }
66    ["sub_array[2,2]"]=>
67    array(1) {
68      [0]=>
69      int(11)
70    }
71    ["sub_array[2,3]"]=>
72    array(2) {
73      [0]=>
74      int(22)
75      [1]=>
76      int(-55)
77    }
78    ["sub_array[2,4]"]=>
79    array(0) {
80    }
81  }
82  ["array1"]=>
83  array(0) {
84  }
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  [0]=>
94  float(0.001)
95  ["-.9"]=>
96  string(3) "-.9"
97  [""]=>
98  string(0) ""
99  [-2]=>
100  float(-2.98989)
101}
102
103-- Testing krsort() by supplying mixed value array, 'flag' value is SORT_REGULAR --
104bool(true)
105array(13) {
106  [5]=>
107  string(1) "5"
108  [4]=>
109  float(4.01)
110  ["b"]=>
111  string(1) "b"
112  ["array2"]=>
113  array(4) {
114    ["sub_array[2,1]"]=>
115    array(3) {
116      [0]=>
117      int(33)
118      [1]=>
119      int(-5)
120      [2]=>
121      int(6)
122    }
123    ["sub_array[2,2]"]=>
124    array(1) {
125      [0]=>
126      int(11)
127    }
128    ["sub_array[2,3]"]=>
129    array(2) {
130      [0]=>
131      int(22)
132      [1]=>
133      int(-55)
134    }
135    ["sub_array[2,4]"]=>
136    array(0) {
137    }
138  }
139  ["array1"]=>
140  array(0) {
141  }
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  [0]=>
151  float(0.001)
152  ["-.9"]=>
153  string(3) "-.9"
154  [""]=>
155  string(0) ""
156  [-2]=>
157  float(-2.98989)
158}
159Done
160