1--TEST--
2Test ksort() function : usage variations - sort array with diff. sub arrays
3--FILE--
4<?php
5/* Prototype  : bool ksort ( 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 ksort() by providing arrays containing 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 ksort() : 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 ksort() by supplying various arrays containing sub arrays --\n";
38
39// loop through to test ksort() 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( ksort($temp_array) );
46  var_dump($temp_array);
47
48  echo "- Sort flag = SORT_REGULAR -\n";
49  $temp_array = $array;
50  var_dump( ksort($temp_array, SORT_REGULAR) );
51  var_dump($temp_array);
52  $count++;
53}
54
55echo "Done\n";
56?>
57--EXPECT--
58*** Testing ksort() : usage variations ***
59
60-- Testing ksort() 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  [1]=>
93  int(11)
94  [3]=>
95  array(2) {
96    [0]=>
97    int(64)
98    [1]=>
99    int(61)
100  }
101  [4]=>
102  int(44)
103}
104- Sort flag = SORT_REGULAR -
105bool(true)
106array(3) {
107  [1]=>
108  int(11)
109  [3]=>
110  array(2) {
111    [0]=>
112    int(64)
113    [1]=>
114    int(61)
115  }
116  [4]=>
117  int(44)
118}
119
120-- Iteration 4 --
121- With defualt sort flag -
122bool(true)
123array(4) {
124  [0]=>
125  array(0) {
126  }
127  [1]=>
128  array(1) {
129    [0]=>
130    int(11)
131  }
132  [2]=>
133  array(2) {
134    [0]=>
135    int(22)
136    [1]=>
137    int(-55)
138  }
139  [3]=>
140  array(3) {
141    [0]=>
142    int(33)
143    [1]=>
144    int(-5)
145    [2]=>
146    int(6)
147  }
148}
149- Sort flag = SORT_REGULAR -
150bool(true)
151array(4) {
152  [0]=>
153  array(0) {
154  }
155  [1]=>
156  array(1) {
157    [0]=>
158    int(11)
159  }
160  [2]=>
161  array(2) {
162    [0]=>
163    int(22)
164    [1]=>
165    int(-55)
166  }
167  [3]=>
168  array(3) {
169    [0]=>
170    int(33)
171    [1]=>
172    int(-5)
173    [2]=>
174    int(6)
175  }
176}
177Done
178