Annotation of embedaddon/php/ext/standard/tests/array/sort_variation9.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test sort() function : usage variations - sort diff. associative arrays, 'sort_flags' as defualt/SORT_REGULAR
3: --FILE--
4: <?php
5: /* Prototype : bool sort ( array &$array [, int $sort_flags] )
6: * Description: This function sorts an array.
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 sort() by providing arrays with key values for $array argument
13: * with following flag values.
14: * 1.flag value as defualt
15: * 2.SORT_REGULAR - compare items normally
16: * To test the new keys for the elements in the sorted array.
17: */
18:
19: echo "*** Testing sort() : usage variations ***\n";
20:
21: // list of arrays with key and values
22: $various_arrays = array(
23: array(5 => 55, 6 => 66, 2 => 22, 3 => 33, 1 => 11),
24: array ("fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"),
25: "numbers" => array(1, 2, 3, 4, 5, 6),
26: "holes" => array("first", 5 => "second", "third")
27: ),
28: array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13),
29: array('bar' => 'baz', "foo" => 1),
30: array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5),
31: );
32:
33: $count = 1;
34: echo "\n-- Testing sort() by supplying various arrays with key values --\n";
35:
36: // loop through to test sort() with different arrays,
37: // to test the new keys for the elements in the sorted array
38: foreach ($various_arrays as $array) {
39: echo "\n-- Iteration $count --\n";
40:
41: echo "- With Defualt sort flag -\n";
42: $temp_array = $array;
43: var_dump(sort($temp_array) );
44: var_dump($temp_array);
45:
46: echo "- Sort flag = SORT_REGULAR -\n";
47: $temp_array = $array;
48: var_dump(sort($temp_array, SORT_REGULAR) );
49: var_dump($temp_array);
50: $count++;
51: }
52:
53: echo "Done\n";
54: ?>
55: --EXPECTF--
56: *** Testing sort() : usage variations ***
57:
58: -- Testing sort() by supplying various arrays with key values --
59:
60: -- Iteration 1 --
61: - With Defualt sort flag -
62: bool(true)
63: array(5) {
64: [0]=>
65: int(11)
66: [1]=>
67: int(22)
68: [2]=>
69: int(33)
70: [3]=>
71: int(55)
72: [4]=>
73: int(66)
74: }
75: - Sort flag = SORT_REGULAR -
76: bool(true)
77: array(5) {
78: [0]=>
79: int(11)
80: [1]=>
81: int(22)
82: [2]=>
83: int(33)
84: [3]=>
85: int(55)
86: [4]=>
87: int(66)
88: }
89:
90: -- Iteration 2 --
91: - With Defualt sort flag -
92: bool(true)
93: array(3) {
94: [0]=>
95: array(3) {
96: [0]=>
97: string(5) "first"
98: [5]=>
99: string(6) "second"
100: [6]=>
101: string(5) "third"
102: }
103: [1]=>
104: array(3) {
105: ["a"]=>
106: string(6) "orange"
107: ["b"]=>
108: string(6) "banana"
109: ["c"]=>
110: string(5) "apple"
111: }
112: [2]=>
113: array(6) {
114: [0]=>
115: int(1)
116: [1]=>
117: int(2)
118: [2]=>
119: int(3)
120: [3]=>
121: int(4)
122: [4]=>
123: int(5)
124: [5]=>
125: int(6)
126: }
127: }
128: - Sort flag = SORT_REGULAR -
129: bool(true)
130: array(3) {
131: [0]=>
132: array(3) {
133: [0]=>
134: string(5) "first"
135: [5]=>
136: string(6) "second"
137: [6]=>
138: string(5) "third"
139: }
140: [1]=>
141: array(3) {
142: ["a"]=>
143: string(6) "orange"
144: ["b"]=>
145: string(6) "banana"
146: ["c"]=>
147: string(5) "apple"
148: }
149: [2]=>
150: array(6) {
151: [0]=>
152: int(1)
153: [1]=>
154: int(2)
155: [2]=>
156: int(3)
157: [3]=>
158: int(4)
159: [4]=>
160: int(5)
161: [5]=>
162: int(6)
163: }
164: }
165:
166: -- Iteration 3 --
167: - With Defualt sort flag -
168: bool(true)
169: array(6) {
170: [0]=>
171: int(1)
172: [1]=>
173: int(1)
174: [2]=>
175: int(1)
176: [3]=>
177: int(1)
178: [4]=>
179: int(13)
180: [5]=>
181: int(19)
182: }
183: - Sort flag = SORT_REGULAR -
184: bool(true)
185: array(6) {
186: [0]=>
187: int(1)
188: [1]=>
189: int(1)
190: [2]=>
191: int(1)
192: [3]=>
193: int(1)
194: [4]=>
195: int(13)
196: [5]=>
197: int(19)
198: }
199:
200: -- Iteration 4 --
201: - With Defualt sort flag -
202: bool(true)
203: array(2) {
204: [0]=>
205: string(3) "baz"
206: [1]=>
207: int(1)
208: }
209: - Sort flag = SORT_REGULAR -
210: bool(true)
211: array(2) {
212: [0]=>
213: string(3) "baz"
214: [1]=>
215: int(1)
216: }
217:
218: -- Iteration 5 --
219: - With Defualt sort flag -
220: bool(true)
221: array(4) {
222: [0]=>
223: int(1)
224: [1]=>
225: int(5)
226: [2]=>
227: array(1) {
228: ["g"]=>
229: int(4)
230: }
231: [3]=>
232: array(2) {
233: ["e"]=>
234: int(2)
235: ["f"]=>
236: int(3)
237: }
238: }
239: - Sort flag = SORT_REGULAR -
240: bool(true)
241: array(4) {
242: [0]=>
243: int(1)
244: [1]=>
245: int(5)
246: [2]=>
247: array(1) {
248: ["g"]=>
249: int(4)
250: }
251: [3]=>
252: array(2) {
253: ["e"]=>
254: int(2)
255: ["f"]=>
256: int(3)
257: }
258: }
259: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>