1--TEST--
2Test usort() function : usage variations - referenced variables
3--FILE--
4<?php
5/* Prototype  : bool usort(array $array_arg, string $cmp_function)
6 * Description: Sort an array by values using a user-defined comparison function
7 * Source code: ext/standard/array.c
8 */
9
10/*
11 * Pass an array of referenced variables as $array_arg to test behaviour
12 */
13
14echo "*** Testing usort() : usage variation ***\n";
15
16function cmp_function($value1, $value2)
17{
18  if($value1 == $value2) {
19    return 0;
20  }
21  else if($value1 > $value2) {
22    return 1;
23  }
24  else {
25    return -1;
26  }
27}
28
29// different variables which are used as elements of $array_arg
30$value1 = -5;
31$value2 = 100;
32$value3 = 0;
33$value4 = &$value1;
34
35// array_args an array containing elements with reference variables
36$array_arg = array(
37  0 => 10,
38  1 => &$value4,
39  2 => &$value2,
40  3 => 200,
41  4 => &$value3,
42);
43
44echo "\n-- Sorting \$array_arg containing different references --\n";
45var_dump( usort($array_arg, 'cmp_function') );
46var_dump($array_arg);
47?>
48===DONE===
49--EXPECT--
50*** Testing usort() : usage variation ***
51
52-- Sorting $array_arg containing different references --
53bool(true)
54array(5) {
55  [0]=>
56  &int(-5)
57  [1]=>
58  &int(0)
59  [2]=>
60  int(10)
61  [3]=>
62  &int(100)
63  [4]=>
64  int(200)
65}
66===DONE===
67