1--TEST--
2Test uasort() function : usage variations - sort different numeric values
3--FILE--
4<?php
5/*
6* sorting different types of numeric arrays containing data of following type:
7*  integer, octal, hexadecimal & float
8*/
9
10// comparison function
11function cmp_function($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
24echo "*** Testing uasort() : different numeric arrays as 'array_arg' ***\n";
25
26// Int array
27$int_values = array(0 => 3, 1 => 2, 3 => 100, 4 => 150, 5 => 25, 6 => 350, 7 => 0, 8 => -3, 9 => -1200);
28echo "-- Sorting Integer array --\n";
29var_dump( uasort($int_values, 'cmp_function') );  // expecting: bool(true)
30var_dump($int_values);
31
32// Octal array
33$octal_values = array(0 => 056, 1 => 023, 2 => 00, 3 => 015, 4 => -045, 5 => 01, 6 => -07);
34echo "-- Sorting Octal array --\n";
35var_dump( uasort($octal_values, 'cmp_function') );  // expecting: bool(true)
36var_dump($octal_values);
37
38// Hexadecimal array
39$hex_values = array(0 => 0xAE, 1 => 0x2B, 2 => 0X10, 3 => -0xCF, 4 => 0X12, 5 => -0XF2);
40echo "-- Sorting Hex array --\n";
41var_dump( uasort($hex_values, 'cmp_function') );  // expecting: bool(true)
42var_dump($hex_values);
43
44// Float array
45$float_values = array( 0 => 10.2, 1 => 2.4, 2 => -3.4, 3 => 0, 4 => 0.5, 5 => 7.3e3, 6 => -9.34E-2);
46echo "-- Sorting Float array --\n";
47var_dump( uasort($float_values, 'cmp_function') );  // expecting: bool(true)
48var_dump($float_values);
49
50// empty array
51$empty_array = array();
52echo "-- Sorting empty array --\n";
53var_dump( uasort($empty_array, 'cmp_function') );  // expecting: bool(true)
54var_dump($empty_array);
55
56echo "Done"
57?>
58--EXPECT--
59*** Testing uasort() : different numeric arrays as 'array_arg' ***
60-- Sorting Integer array --
61bool(true)
62array(9) {
63  [9]=>
64  int(-1200)
65  [8]=>
66  int(-3)
67  [7]=>
68  int(0)
69  [1]=>
70  int(2)
71  [0]=>
72  int(3)
73  [5]=>
74  int(25)
75  [3]=>
76  int(100)
77  [4]=>
78  int(150)
79  [6]=>
80  int(350)
81}
82-- Sorting Octal array --
83bool(true)
84array(7) {
85  [4]=>
86  int(-37)
87  [6]=>
88  int(-7)
89  [2]=>
90  int(0)
91  [5]=>
92  int(1)
93  [3]=>
94  int(13)
95  [1]=>
96  int(19)
97  [0]=>
98  int(46)
99}
100-- Sorting Hex array --
101bool(true)
102array(6) {
103  [5]=>
104  int(-242)
105  [3]=>
106  int(-207)
107  [2]=>
108  int(16)
109  [4]=>
110  int(18)
111  [1]=>
112  int(43)
113  [0]=>
114  int(174)
115}
116-- Sorting Float array --
117bool(true)
118array(7) {
119  [2]=>
120  float(-3.4)
121  [6]=>
122  float(-0.0934)
123  [3]=>
124  int(0)
125  [4]=>
126  float(0.5)
127  [1]=>
128  float(2.4)
129  [0]=>
130  float(10.2)
131  [5]=>
132  float(7300)
133}
134-- Sorting empty array --
135bool(true)
136array(0) {
137}
138Done
139