Annotation of embedaddon/php/ext/standard/tests/array/krsort_variation8.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test 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:
17: echo "*** 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:
31: echo "\n-- Testing krsort() by supplying mixed value array, 'flag' value is defualt --\n";
32: $temp_array = $mixed_values;
33: var_dump( krsort($temp_array) );
34: var_dump($temp_array);
35:
36: echo "\n-- Testing krsort() by supplying mixed value array, 'flag' value is SORT_REGULAR --\n";
37: $temp_array = $mixed_values;
38: var_dump( krsort($temp_array, SORT_REGULAR) );
39: var_dump($temp_array);
40:
41: echo "Done\n";
42: ?>
43: --EXPECTF--
44: *** Testing krsort() : usage variations ***
45:
46: -- Testing krsort() by supplying mixed value array, 'flag' value is defualt --
47: bool(true)
48: array(13) {
49: [5]=>
50: string(1) "5"
51: [4]=>
52: float(4.01)
53: [0]=>
54: float(0.001)
55: ["b"]=>
56: string(1) "b"
57: ["array2"]=>
58: array(4) {
59: ["sub_array[2,1]"]=>
60: array(3) {
61: [0]=>
62: int(33)
63: [1]=>
64: int(-5)
65: [2]=>
66: int(6)
67: }
68: ["sub_array[2,2]"]=>
69: array(1) {
70: [0]=>
71: int(11)
72: }
73: ["sub_array[2,3]"]=>
74: array(2) {
75: [0]=>
76: int(22)
77: [1]=>
78: int(-55)
79: }
80: ["sub_array[2,4]"]=>
81: array(0) {
82: }
83: }
84: ["array1"]=>
85: array(0) {
86: }
87: ["abcd abcd abcd"]=>
88: string(14) "abcd abcd abcd"
89: ["abcd"]=>
90: string(4) "abcd"
91: ["ab"]=>
92: string(2) "ab"
93: ["True"]=>
94: string(4) "True"
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 --
104: bool(true)
105: array(13) {
106: [5]=>
107: string(1) "5"
108: [4]=>
109: float(4.01)
110: [0]=>
111: float(0.001)
112: ["b"]=>
113: string(1) "b"
114: ["array2"]=>
115: array(4) {
116: ["sub_array[2,1]"]=>
117: array(3) {
118: [0]=>
119: int(33)
120: [1]=>
121: int(-5)
122: [2]=>
123: int(6)
124: }
125: ["sub_array[2,2]"]=>
126: array(1) {
127: [0]=>
128: int(11)
129: }
130: ["sub_array[2,3]"]=>
131: array(2) {
132: [0]=>
133: int(22)
134: [1]=>
135: int(-55)
136: }
137: ["sub_array[2,4]"]=>
138: array(0) {
139: }
140: }
141: ["array1"]=>
142: array(0) {
143: }
144: ["abcd abcd abcd"]=>
145: string(14) "abcd abcd abcd"
146: ["abcd"]=>
147: string(4) "abcd"
148: ["ab"]=>
149: string(2) "ab"
150: ["True"]=>
151: string(4) "True"
152: ["-.9"]=>
153: string(3) "-.9"
154: [""]=>
155: string(0) ""
156: [-2]=>
157: float(-2.98989)
158: }
159: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>