1--TEST--
2Test asort() function : usage variations - sort reference variables
3--FILE--
4<?php
5/* Prototype  : bool asort ( array &$array [, int $sort_flags] )
6 * Description: Sort an array and maintain index association.
7                Elements will be arranged from lowest to highest when this function has completed.
8 * Source code: ext/standard/array.c
9*/
10
11/*
12 * Testing asort() by providing reference variable array with following flag values
13 *  flag value as defualt
14 *  SORT_REGULAR - compare items normally
15 *  SORT_NUMERIC - compare items numerically
16*/
17
18echo "*** Testing asort() :usage variations  ***\n";
19
20$value1 = 100;
21$value2 = 33;
22$value3 = 555;
23
24// an array containing integer references
25$unsorted_numerics =  array( 1 => &$value1 , 2 => &$value2, 3 => &$value3);
26
27echo "\n-- Testing asort() by supplying reference variable array, 'flag' value is defualt --\n";
28$temp_array = $unsorted_numerics;
29var_dump( asort($temp_array) ); // expecting : bool(true)
30var_dump( $temp_array);
31
32echo "\n-- Testing asort() by supplying reference variable array, 'flag' = SORT_REGULAR --\n";
33$temp_array = &$unsorted_numerics;
34var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
35var_dump( $temp_array);
36
37echo "\n-- Testing asort() by supplying reference variable array, 'flag' = SORT_NUMERIC --\n";
38$temp_array = &$unsorted_numerics;
39var_dump( asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
40var_dump( $temp_array);
41
42echo "Done\n";
43?>
44--EXPECT--
45*** Testing asort() :usage variations  ***
46
47-- Testing asort() by supplying reference variable array, 'flag' value is defualt --
48bool(true)
49array(3) {
50  [2]=>
51  &int(33)
52  [1]=>
53  &int(100)
54  [3]=>
55  &int(555)
56}
57
58-- Testing asort() by supplying reference variable array, 'flag' = SORT_REGULAR --
59bool(true)
60array(3) {
61  [2]=>
62  &int(33)
63  [1]=>
64  &int(100)
65  [3]=>
66  &int(555)
67}
68
69-- Testing asort() by supplying reference variable array, 'flag' = SORT_NUMERIC --
70bool(true)
71array(3) {
72  [2]=>
73  &int(33)
74  [1]=>
75  &int(100)
76  [3]=>
77  &int(555)
78}
79Done
80