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