Annotation of embedaddon/php/ext/standard/tests/array/arsort_basic.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test arsort() function : basic functionality
3: --FILE--
4: <?php
5: /* Prototype : bool arsort ( array &$array [, int $sort_flags] )
6: * Description: Sort an array and maintain index association
7: Elements will be arranged from highest to lowest when this function has completed.
8: * Source code: ext/standard/array.c
9: */
10:
11: /*
12: * Testing arsort() by providing integer/string arrays to check the basic functionality
13: * with following flag values.
14: * flag value as default
15: * SORT_REGULAR - compare items normally
16: * SORT_NUMERIC - compare items numerically
17: * SORT_STRING - compare items as strings
18: */
19:
20: echo "*** Testing arsort() : basic functionality ***\n";
21:
22: // an array containing unsorted string values with indices
23: $unsorted_strings = array( "l" => "lemon", "o" => "orange", "b" => "banana" );
24: // an array containing unsorted numeric values with indices
25: $unsorted_numerics = array( 1 => 100, 2 => 33, 3 => 555, 4 => 22 );
26:
27: echo "\n-- Testing arsort() by supplying string array, 'flag' value is default --\n";
28: $temp_array = $unsorted_strings;
29: var_dump( arsort($temp_array) ); // expecting : bool(true)
30: var_dump( $temp_array);
31:
32: echo "\n-- Testing arsort() by supplying numeric array, 'flag' value is default --\n";
33: $temp_array = $unsorted_numerics;
34: var_dump( arsort($temp_array) ); // expecting : bool(true)
35: var_dump( $temp_array);
36:
37: echo "\n-- Testing arsort() by supplying string array, 'flag' = SORT_REGULAR --\n";
38: $temp_array = $unsorted_strings;
39: var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
40: var_dump( $temp_array);
41:
42: echo "\n-- Testing arsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n";
43: $temp_array = $unsorted_numerics;
44: var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
45: var_dump( $temp_array);
46:
47: echo "\n-- Testing arsort() by supplying string array, 'flag' = SORT_STRING --\n";
48: $temp_array = $unsorted_strings;
49: var_dump( arsort($temp_array, SORT_STRING) ); // expecting : bool(true)
50: var_dump( $temp_array);
51:
52: echo "\n-- Testing arsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
53: $temp_array = $unsorted_numerics;
54: var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
55: var_dump( $temp_array);
56:
57: echo "Done\n";
58: ?>
59: --EXPECTF--
60: *** Testing arsort() : basic functionality ***
61:
62: -- Testing arsort() by supplying string array, 'flag' value is default --
63: bool(true)
64: array(3) {
65: ["o"]=>
66: string(6) "orange"
67: ["l"]=>
68: string(5) "lemon"
69: ["b"]=>
70: string(6) "banana"
71: }
72:
73: -- Testing arsort() by supplying numeric array, 'flag' value is default --
74: bool(true)
75: array(4) {
76: [3]=>
77: int(555)
78: [1]=>
79: int(100)
80: [2]=>
81: int(33)
82: [4]=>
83: int(22)
84: }
85:
86: -- Testing arsort() by supplying string array, 'flag' = SORT_REGULAR --
87: bool(true)
88: array(3) {
89: ["o"]=>
90: string(6) "orange"
91: ["l"]=>
92: string(5) "lemon"
93: ["b"]=>
94: string(6) "banana"
95: }
96:
97: -- Testing arsort() by supplying numeric array, 'flag' = SORT_REGULAR --
98: bool(true)
99: array(4) {
100: [3]=>
101: int(555)
102: [1]=>
103: int(100)
104: [2]=>
105: int(33)
106: [4]=>
107: int(22)
108: }
109:
110: -- Testing arsort() by supplying string array, 'flag' = SORT_STRING --
111: bool(true)
112: array(3) {
113: ["o"]=>
114: string(6) "orange"
115: ["l"]=>
116: string(5) "lemon"
117: ["b"]=>
118: string(6) "banana"
119: }
120:
121: -- Testing arsort() by supplying numeric array, 'flag' = SORT_NUMERIC --
122: bool(true)
123: array(4) {
124: [3]=>
125: int(555)
126: [1]=>
127: int(100)
128: [2]=>
129: int(33)
130: [4]=>
131: int(22)
132: }
133: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>