1--TEST--
2Test krsort() function : usage variations - sort array with diff. sub arrays
3--FILE--
4<?php
5/* Prototype  : bool krsort ( array &$array [, int $sort_flags] )
6 * Description: Sort an array by key, maintaining key to data correlation
7 * Source code: ext/standard/array.c
8*/
9
10/*
11 * testing krsort() by providing arrays contains sub arrays for $array argument
12 * with flowing flag values
13 *  1.flag  value as defualt
14 *  2.SORT_REGULAR - compare items normally
15*/
16
17echo "*** Testing krsort() : usage variations ***\n";
18
19// array with diff sub arrays to be sorted
20$various_arrays = array (
21  // null array
22  1  => array(),
23
24  // array contains null sub array
25  2 => array( 1 => array() ),
26
27  // array of arrays along with some values
28  3 => array(4 => 44, 1 => 11, 3 => array(64,61) ),
29
30  // array contains sub arrays
31  4 => array ( 3 => array(33,-5,6), 1 => array(11),
32               2 => array(22,-55), 0  => array() )
33);
34
35
36$count = 1;
37echo "\n-- Testing krsort() by supplying various arrays containing sub arrays --\n";
38
39// loop through to test krsort() with different arrays
40foreach ($various_arrays as $array) {
41
42  echo "\n-- Iteration $count --\n";
43  echo "- With defualt sort flag -\n";
44  $temp_array = $array;
45  var_dump( krsort($temp_array) );
46  var_dump($temp_array);
47
48  echo "- Sort flag = SORT_REGULAR -\n";
49  $temp_array = $array;
50  var_dump( krsort($temp_array, SORT_REGULAR) );
51  var_dump($temp_array);
52  $count++;
53}
54
55echo "Done\n";
56?>
57--EXPECT--
58*** Testing krsort() : usage variations ***
59
60-- Testing krsort() by supplying various arrays containing sub arrays --
61
62-- Iteration 1 --
63- With defualt sort flag -
64bool(true)
65array(0) {
66}
67- Sort flag = SORT_REGULAR -
68bool(true)
69array(0) {
70}
71
72-- Iteration 2 --
73- With defualt sort flag -
74bool(true)
75array(1) {
76  [1]=>
77  array(0) {
78  }
79}
80- Sort flag = SORT_REGULAR -
81bool(true)
82array(1) {
83  [1]=>
84  array(0) {
85  }
86}
87
88-- Iteration 3 --
89- With defualt sort flag -
90bool(true)
91array(3) {
92  [4]=>
93  int(44)
94  [3]=>
95  array(2) {
96    [0]=>
97    int(64)
98    [1]=>
99    int(61)
100  }
101  [1]=>
102  int(11)
103}
104- Sort flag = SORT_REGULAR -
105bool(true)
106array(3) {
107  [4]=>
108  int(44)
109  [3]=>
110  array(2) {
111    [0]=>
112    int(64)
113    [1]=>
114    int(61)
115  }
116  [1]=>
117  int(11)
118}
119
120-- Iteration 4 --
121- With defualt sort flag -
122bool(true)
123array(4) {
124  [3]=>
125  array(3) {
126    [0]=>
127    int(33)
128    [1]=>
129    int(-5)
130    [2]=>
131    int(6)
132  }
133  [2]=>
134  array(2) {
135    [0]=>
136    int(22)
137    [1]=>
138    int(-55)
139  }
140  [1]=>
141  array(1) {
142    [0]=>
143    int(11)
144  }
145  [0]=>
146  array(0) {
147  }
148}
149- Sort flag = SORT_REGULAR -
150bool(true)
151array(4) {
152  [3]=>
153  array(3) {
154    [0]=>
155    int(33)
156    [1]=>
157    int(-5)
158    [2]=>
159    int(6)
160  }
161  [2]=>
162  array(2) {
163    [0]=>
164    int(22)
165    [1]=>
166    int(-55)
167  }
168  [1]=>
169  array(1) {
170    [0]=>
171    int(11)
172  }
173  [0]=>
174  array(0) {
175  }
176}
177Done
178