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