1--TEST--
2Test krsort() function : usage variations - sort hexadecimal values
3--FILE--
4<?php
5/* Prototype  : bool krsort ( array &$array [, int $sort_flags] )
6 * Description: Sort an array by key in reverse order, maintaining key to data correlation.
7 * Source code: ext/standard/array.c
8*/
9
10/*
11 * testing krsort() by providing array of hexa-decimal values for $array argument
12 * with following flag values:
13 *  1.flag value as defualt
14 *  2.SORT_REGULAR - compare items normally
15 *  3.SORT_NUMERIC - compare items numerically
16*/
17
18echo "*** Testing krsort() : usage variations ***\n";
19
20// an array containing unsorted hexadecimal values with keys
21$unsorted_hex_array = array (
22  0x1AB => 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB,
23  0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa
24);
25
26echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is defualt  --\n";
27$temp_array = $unsorted_hex_array;
28var_dump(krsort( $temp_array) ); // expecting : bool(true)
29var_dump($temp_array);
30
31echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR  --\n";
32$temp_array = $unsorted_hex_array;
33var_dump(krsort( $temp_array, SORT_REGULAR) ); // expecting : bool(true)
34var_dump($temp_array);
35
36echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC  --\n";
37$temp_array = $unsorted_hex_array;
38var_dump(krsort( $temp_array, SORT_NUMERIC) ); // expecting : bool(true)
39var_dump($temp_array);
40
41echo "Done\n";
42?>
43--EXPECT--
44*** Testing krsort() : usage variations ***
45
46-- Testing krsort() by supplying hexadecimal value array, 'flag' value is defualt  --
47bool(true)
48array(9) {
49  [4095]=>
50  int(4095)
51  [682]=>
52  int(682)
53  [427]=>
54  int(427)
55  [255]=>
56  int(255)
57  [187]=>
58  int(187)
59  [15]=>
60  int(15)
61  [0]=>
62  int(0)
63  [-255]=>
64  int(-255)
65  [-682]=>
66  int(-682)
67}
68
69-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR  --
70bool(true)
71array(9) {
72  [4095]=>
73  int(4095)
74  [682]=>
75  int(682)
76  [427]=>
77  int(427)
78  [255]=>
79  int(255)
80  [187]=>
81  int(187)
82  [15]=>
83  int(15)
84  [0]=>
85  int(0)
86  [-255]=>
87  int(-255)
88  [-682]=>
89  int(-682)
90}
91
92-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC  --
93bool(true)
94array(9) {
95  [4095]=>
96  int(4095)
97  [682]=>
98  int(682)
99  [427]=>
100  int(427)
101  [255]=>
102  int(255)
103  [187]=>
104  int(187)
105  [15]=>
106  int(15)
107  [0]=>
108  int(0)
109  [-255]=>
110  int(-255)
111  [-682]=>
112  int(-682)
113}
114Done
115