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