1--TEST--
2Test krsort() function : usage variations - sort octal 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 octal 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 octal values
21$unsorted_oct_array = array (
22  01235 => 01, 0321 => 02, 0345 => 03, 066 => 04, 0772 => 05,
23  077 => 06, -066 => -01, -0345 => -02, 0 => 0
24);
25
26echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is defualt  --\n";
27$temp_array = $unsorted_oct_array;
28var_dump( krsort($temp_array) ); // expecting : bool(true)
29var_dump($temp_array);
30
31echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR  --\n";
32$temp_array = $unsorted_oct_array;
33var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
34var_dump($temp_array);
35
36echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC  --\n";
37$temp_array = $unsorted_oct_array;
38var_dump( krsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
39var_dump($temp_array);
40
41echo "Done\n";
42?>
43--EXPECTF--
44*** Testing krsort() : usage variations ***
45
46-- Testing krsort() by supplying octal value array, 'flag' value is defualt  --
47bool(true)
48array(9) {
49  [669]=>
50  int(1)
51  [506]=>
52  int(5)
53  [229]=>
54  int(3)
55  [209]=>
56  int(2)
57  [63]=>
58  int(6)
59  [54]=>
60  int(4)
61  [0]=>
62  int(0)
63  [-54]=>
64  int(-1)
65  [-229]=>
66  int(-2)
67}
68
69-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR  --
70bool(true)
71array(9) {
72  [669]=>
73  int(1)
74  [506]=>
75  int(5)
76  [229]=>
77  int(3)
78  [209]=>
79  int(2)
80  [63]=>
81  int(6)
82  [54]=>
83  int(4)
84  [0]=>
85  int(0)
86  [-54]=>
87  int(-1)
88  [-229]=>
89  int(-2)
90}
91
92-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC  --
93bool(true)
94array(9) {
95  [669]=>
96  int(1)
97  [506]=>
98  int(5)
99  [229]=>
100  int(3)
101  [209]=>
102  int(2)
103  [63]=>
104  int(6)
105  [54]=>
106  int(4)
107  [0]=>
108  int(0)
109  [-54]=>
110  int(-1)
111  [-229]=>
112  int(-2)
113}
114Done
115