1--TEST--
2Test usort() function : usage variations - multi-dimensional arrays
3--FILE--
4<?php
5/*
6 * Pass a multi-dimensional array as $array_arg argument to usort()
7 * to test how array is re-ordered
8 */
9
10echo "*** Testing usort() : usage variation ***\n";
11
12function cmp_function($value1, $value2)
13{
14  if($value1 == $value2) {
15    return 0;
16  }
17  else if($value1 > $value2) {
18    return 1;
19  }
20  else {
21    return -1;
22  }
23}
24
25$array_args = array(
26  0 => array(2, 10, -1),
27  1 => array(100),
28  2 => array(),
29  3 => array(0),
30  4 => array(-1),
31  5 => array(-9, 34, 54, 0, 20),
32  6 => array(''),
33  7 => array("apple", "Apple", "APPLE", "aPPle", "aPpLe")
34);
35
36$temp_array = $array_args;
37
38echo "\n-- Pass usort() a two-dimensional array --\n";
39// sorting array_arg as whole array
40var_dump( usort($temp_array, 'cmp_function') );
41
42echo "-- Array after call to usort() --\n";
43var_dump($temp_array);
44
45echo "\n-- Pass usort() a sub-array --\n";
46var_dump( usort($array_args[5], 'cmp_function') );
47
48echo "-- Array after call to usort() --\n";
49var_dump($array_args[5]);
50?>
51--EXPECT--
52*** Testing usort() : usage variation ***
53
54-- Pass usort() a two-dimensional array --
55bool(true)
56-- Array after call to usort() --
57array(8) {
58  [0]=>
59  array(0) {
60  }
61  [1]=>
62  array(1) {
63    [0]=>
64    string(0) ""
65  }
66  [2]=>
67  array(1) {
68    [0]=>
69    int(-1)
70  }
71  [3]=>
72  array(1) {
73    [0]=>
74    int(0)
75  }
76  [4]=>
77  array(1) {
78    [0]=>
79    int(100)
80  }
81  [5]=>
82  array(3) {
83    [0]=>
84    int(2)
85    [1]=>
86    int(10)
87    [2]=>
88    int(-1)
89  }
90  [6]=>
91  array(5) {
92    [0]=>
93    int(-9)
94    [1]=>
95    int(34)
96    [2]=>
97    int(54)
98    [3]=>
99    int(0)
100    [4]=>
101    int(20)
102  }
103  [7]=>
104  array(5) {
105    [0]=>
106    string(5) "apple"
107    [1]=>
108    string(5) "Apple"
109    [2]=>
110    string(5) "APPLE"
111    [3]=>
112    string(5) "aPPle"
113    [4]=>
114    string(5) "aPpLe"
115  }
116}
117
118-- Pass usort() a sub-array --
119bool(true)
120-- Array after call to usort() --
121array(5) {
122  [0]=>
123  int(-9)
124  [1]=>
125  int(0)
126  [2]=>
127  int(20)
128  [3]=>
129  int(34)
130  [4]=>
131  int(54)
132}
133