1--TEST--
2Test usort() function : basic functionality
3--FILE--
4<?php
5/*
6 * Test basic functionality of usort() with indexed and associative arrays
7 */
8
9echo "*** Testing usort() : basic functionality ***\n";
10
11function cmp($value1, $value2)
12{
13  if($value1 == $value2) {
14    return 0;
15  }
16  else if($value1 > $value2) {
17    return 1;
18  }
19  else
20    return -1;
21}
22
23// Int array with default keys
24$int_values = array(1, 8, 9, 3, 2, 6, 7);
25
26echo "\n-- Numeric array with default keys --\n";
27var_dump( usort($int_values, 'cmp') );
28var_dump($int_values);
29
30// String array with default keys
31$string_values = array("This", "is", 'a', "test");
32
33echo "\n-- String array with default keys --\n";
34var_dump( usort($string_values, 'cmp') );
35var_dump($string_values);
36
37// Associative array with numeric keys
38$numeric_key_arg = array(1=> 1, 2 => 2, 3 => 7, 5 => 4, 4 => 9);
39
40echo "\n-- Associative array with numeric keys --\n";
41var_dump( usort($numeric_key_arg, 'cmp') );
42var_dump($numeric_key_arg);
43
44// Associative array with string keys
45$string_key_arg = array('one' => 4, 'two' => 2, 'three' => 1, 'four' => 10);
46
47echo "\n-- Associative array with string keys --\n";
48var_dump( usort($string_key_arg, 'cmp') );
49var_dump($string_key_arg);
50?>
51--EXPECT--
52*** Testing usort() : basic functionality ***
53
54-- Numeric array with default keys --
55bool(true)
56array(7) {
57  [0]=>
58  int(1)
59  [1]=>
60  int(2)
61  [2]=>
62  int(3)
63  [3]=>
64  int(6)
65  [4]=>
66  int(7)
67  [5]=>
68  int(8)
69  [6]=>
70  int(9)
71}
72
73-- String array with default keys --
74bool(true)
75array(4) {
76  [0]=>
77  string(4) "This"
78  [1]=>
79  string(1) "a"
80  [2]=>
81  string(2) "is"
82  [3]=>
83  string(4) "test"
84}
85
86-- Associative array with numeric keys --
87bool(true)
88array(5) {
89  [0]=>
90  int(1)
91  [1]=>
92  int(2)
93  [2]=>
94  int(4)
95  [3]=>
96  int(7)
97  [4]=>
98  int(9)
99}
100
101-- Associative array with string keys --
102bool(true)
103array(4) {
104  [0]=>
105  int(1)
106  [1]=>
107  int(2)
108  [2]=>
109  int(4)
110  [3]=>
111  int(10)
112}
113