Annotation of embedaddon/php/ext/standard/tests/array/krsort_variation5.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test krsort() function : usage variations - sort strings
3: --SKIPIF--
4: <?php
5: if (substr(PHP_OS, 0, 3) == 'WIN') {
6: die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)");
7: }
8: --FILE--
9: <?php
10: /* Prototype : bool krsort ( array &$array [, int $sort_flags] )
11: * Description: Sort an array by key in reverse order, maintaining key to data correlation
12: * Source code: ext/standard/array.c
13: */
14:
15: /*
16: * testing krsort() by providing array of string values for $array argument with
17: * following flag values:
18: * 1.flag value as defualt
19: * 2.SORT_REGULAR - compare items normally
20: * 3.SORT_STRING - compare items as strings
21: */
22:
23: echo "*** Testing krsort() : usage variations ***\n";
24:
25: $various_arrays = array (
26: // diff. escape sequence chars with key values
27: array ( null => null, NULL => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e",
28: "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh",
29: "\ddd" => "\ddd", "\v" => "\v"
30: ),
31:
32: // array containing different strings with key values
33: array ( 'Lemon' => "lemoN", 'o' => "Orange", 'B' => "banana", 'Apple' => "apple", 'te' => "Test",
34: 't' => "TTTT", 'T' => "ttt", 'W' => "ww", 'X' => "x", 'x' => "X", 'O' => "oraNGe",
35: 'B' => "BANANA"
36: )
37: );
38:
39: $flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING);
40:
41: $count = 1;
42: echo "\n-- Testing krsort() by supplying various string arrays --\n";
43:
44: // loop through to test krsort() with different arrays
45: foreach ($various_arrays as $array) {
46: echo "\n-- Iteration $count --\n";
47:
48: echo "- With defualt sort flag -\n";
49: $temp_array = $array;
50: var_dump(krsort($temp_array) ); // expecting : bool(true)
51: var_dump($temp_array);
52:
53: // loop through $flags array and call krsort() with all possible sort flag values
54: foreach($flags as $key => $flag){
55: echo "- Sort flag = $key -\n";
56: $temp_array = $array;
57: var_dump(krsort($temp_array, $flag) ); // expecting : bool(true)
58: var_dump($temp_array);
59: }
60: $count++;
61: }
62:
63: echo "Done\n";
64: ?>
65: --EXPECTF--
66: *** Testing krsort() : usage variations ***
67:
68: -- Testing krsort() by supplying various string arrays --
69:
70: -- Iteration 1 --
71: - With defualt sort flag -
72: bool(true)
73: array(11) {
74: ["\xhh"]=>
75: string(4) "\xhh"
76: ["\e"]=>
77: string(2) "\e"
78: ["\ddd"]=>
79: string(4) "\ddd"
80: ["\cx"]=>
81: string(3) "\cx"
82: ["\a"]=>
83: string(2) "\a"
84: ["
85: "]=>
86: string(1) "
87: "
88: [""]=>
89: string(1) ""
90: [""]=>
91: string(1) ""
92: ["
93: "]=>
94: string(1) "
95: "
96: [" "]=>
97: string(1) " "
98: [""]=>
99: NULL
100: }
101: - Sort flag = SORT_REGULAR -
102: bool(true)
103: array(11) {
104: ["\xhh"]=>
105: string(4) "\xhh"
106: ["\e"]=>
107: string(2) "\e"
108: ["\ddd"]=>
109: string(4) "\ddd"
110: ["\cx"]=>
111: string(3) "\cx"
112: ["\a"]=>
113: string(2) "\a"
114: ["
115: "]=>
116: string(1) "
117: "
118: [""]=>
119: string(1) ""
120: [""]=>
121: string(1) ""
122: ["
123: "]=>
124: string(1) "
125: "
126: [" "]=>
127: string(1) " "
128: [""]=>
129: NULL
130: }
131: - Sort flag = SORT_STRING -
132: bool(true)
133: array(11) {
134: ["\xhh"]=>
135: string(4) "\xhh"
136: ["\e"]=>
137: string(2) "\e"
138: ["\ddd"]=>
139: string(4) "\ddd"
140: ["\cx"]=>
141: string(3) "\cx"
142: ["\a"]=>
143: string(2) "\a"
144: ["
145: "]=>
146: string(1) "
147: "
148: [""]=>
149: string(1) ""
150: [""]=>
151: string(1) ""
152: ["
153: "]=>
154: string(1) "
155: "
156: [" "]=>
157: string(1) " "
158: [""]=>
159: NULL
160: }
161:
162: -- Iteration 2 --
163: - With defualt sort flag -
164: bool(true)
165: array(11) {
166: ["x"]=>
167: string(1) "X"
168: ["te"]=>
169: string(4) "Test"
170: ["t"]=>
171: string(4) "TTTT"
172: ["o"]=>
173: string(6) "Orange"
174: ["X"]=>
175: string(1) "x"
176: ["W"]=>
177: string(2) "ww"
178: ["T"]=>
179: string(3) "ttt"
180: ["O"]=>
181: string(6) "oraNGe"
182: ["Lemon"]=>
183: string(5) "lemoN"
184: ["B"]=>
185: string(6) "BANANA"
186: ["Apple"]=>
187: string(5) "apple"
188: }
189: - Sort flag = SORT_REGULAR -
190: bool(true)
191: array(11) {
192: ["x"]=>
193: string(1) "X"
194: ["te"]=>
195: string(4) "Test"
196: ["t"]=>
197: string(4) "TTTT"
198: ["o"]=>
199: string(6) "Orange"
200: ["X"]=>
201: string(1) "x"
202: ["W"]=>
203: string(2) "ww"
204: ["T"]=>
205: string(3) "ttt"
206: ["O"]=>
207: string(6) "oraNGe"
208: ["Lemon"]=>
209: string(5) "lemoN"
210: ["B"]=>
211: string(6) "BANANA"
212: ["Apple"]=>
213: string(5) "apple"
214: }
215: - Sort flag = SORT_STRING -
216: bool(true)
217: array(11) {
218: ["x"]=>
219: string(1) "X"
220: ["te"]=>
221: string(4) "Test"
222: ["t"]=>
223: string(4) "TTTT"
224: ["o"]=>
225: string(6) "Orange"
226: ["X"]=>
227: string(1) "x"
228: ["W"]=>
229: string(2) "ww"
230: ["T"]=>
231: string(3) "ttt"
232: ["O"]=>
233: string(6) "oraNGe"
234: ["Lemon"]=>
235: string(5) "lemoN"
236: ["B"]=>
237: string(6) "BANANA"
238: ["Apple"]=>
239: string(5) "apple"
240: }
241: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>