Annotation of embedaddon/php/ext/standard/tests/array/sort_variation6.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test sort() function : usage variations - sort hexadecimal values
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 different hexa-decimal array for $array argument with following flag values
13: * flag value as defualt
14: * SORT_REGULAR - compare items normally
15: * SORT_NUMERIC - compare items numerically
16: */
17:
18: echo "*** Testing sort() : usage variations ***\n";
19:
20: // an array contains unsorted hexadecimal values
21: $unsorted_hex_array = array(0x1AB, 0xFFF, 0xF, 0xFF, 0x2AA, 0xBB, 0x1ab, 0xff, -0xFF, 0, -0x2aa);
22:
23: echo "\n-- Testing sort() by supplying hexadecimal value array, 'flag' value is defualt --\n";
24: $temp_array = $unsorted_hex_array;
25: var_dump(sort($temp_array) ); // expecting : bool(true)
26: var_dump($temp_array);
27:
28: echo "\n-- Testing sort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n";
29: $temp_array = $unsorted_hex_array;
30: var_dump(sort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
31: var_dump($temp_array);
32:
33: echo "\n-- Testing sort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n";
34: $temp_array = $unsorted_hex_array;
35: var_dump(sort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
36: var_dump($temp_array);
37:
38: echo "Done\n";
39: ?>
40: --EXPECTF--
41: *** Testing sort() : usage variations ***
42:
43: -- Testing sort() by supplying hexadecimal value array, 'flag' value is defualt --
44: bool(true)
45: array(11) {
46: [0]=>
47: int(-682)
48: [1]=>
49: int(-255)
50: [2]=>
51: int(0)
52: [3]=>
53: int(15)
54: [4]=>
55: int(187)
56: [5]=>
57: int(255)
58: [6]=>
59: int(255)
60: [7]=>
61: int(427)
62: [8]=>
63: int(427)
64: [9]=>
65: int(682)
66: [10]=>
67: int(4095)
68: }
69:
70: -- Testing sort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --
71: bool(true)
72: array(11) {
73: [0]=>
74: int(-682)
75: [1]=>
76: int(-255)
77: [2]=>
78: int(0)
79: [3]=>
80: int(15)
81: [4]=>
82: int(187)
83: [5]=>
84: int(255)
85: [6]=>
86: int(255)
87: [7]=>
88: int(427)
89: [8]=>
90: int(427)
91: [9]=>
92: int(682)
93: [10]=>
94: int(4095)
95: }
96:
97: -- Testing sort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --
98: bool(true)
99: array(11) {
100: [0]=>
101: int(-682)
102: [1]=>
103: int(-255)
104: [2]=>
105: int(0)
106: [3]=>
107: int(15)
108: [4]=>
109: int(187)
110: [5]=>
111: int(255)
112: [6]=>
113: int(255)
114: [7]=>
115: int(427)
116: [8]=>
117: int(427)
118: [9]=>
119: int(682)
120: [10]=>
121: int(4095)
122: }
123: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>