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