1--TEST--
2Test asort() function : basic functionality
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 integer/string arrays to check the basic functionality
13 * with following flag values.
14 *  flag value as default
15 *  SORT_REGULAR - compare items normally
16 *  SORT_NUMERIC - compare items numerically
17 *  SORT_STRING - compare items as strings
18*/
19
20echo "*** Testing asort() : basic functionality ***\n";
21
22// an array containing unsorted string values with indices
23$unsorted_strings =   array( "l" => "lemon", "o" => "orange", "b" => "banana" );
24// an array containing unsorted numeric values with indices
25$unsorted_numerics =  array( 1 => 100, 2 => 33, 3 => 555, 4 => 22 );
26
27echo "\n-- Testing asort() by supplying string array, 'flag' value is default --\n";
28$temp_array = $unsorted_strings;
29var_dump( asort($temp_array) ); // expecting : bool(true)
30var_dump( $temp_array);
31
32echo "\n-- Testing asort() by supplying numeric array, 'flag' value is default --\n";
33$temp_array = $unsorted_numerics;
34var_dump( asort($temp_array) ); // expecting : bool(true)
35var_dump( $temp_array);
36
37echo "\n-- Testing asort() by supplying string array, 'flag' = SORT_REGULAR --\n";
38$temp_array = $unsorted_strings;
39var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
40var_dump( $temp_array);
41
42echo "\n-- Testing asort() by supplying numeric array, 'flag' = SORT_REGULAR --\n";
43$temp_array = $unsorted_numerics;
44var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true)
45var_dump( $temp_array);
46
47echo "\n-- Testing asort() by supplying string array, 'flag' = SORT_STRING --\n";
48$temp_array = $unsorted_strings;
49var_dump( asort($temp_array, SORT_STRING) ); // expecting : bool(true)
50var_dump( $temp_array);
51
52echo "\n-- Testing asort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
53$temp_array = $unsorted_numerics;
54var_dump( asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true)
55var_dump( $temp_array);
56
57echo "Done\n";
58?>
59--EXPECTF--
60*** Testing asort() : basic functionality ***
61
62-- Testing asort() by supplying string array, 'flag' value is default --
63bool(true)
64array(3) {
65  ["b"]=>
66  string(6) "banana"
67  ["l"]=>
68  string(5) "lemon"
69  ["o"]=>
70  string(6) "orange"
71}
72
73-- Testing asort() by supplying numeric array, 'flag' value is default --
74bool(true)
75array(4) {
76  [4]=>
77  int(22)
78  [2]=>
79  int(33)
80  [1]=>
81  int(100)
82  [3]=>
83  int(555)
84}
85
86-- Testing asort() by supplying string array, 'flag' = SORT_REGULAR --
87bool(true)
88array(3) {
89  ["b"]=>
90  string(6) "banana"
91  ["l"]=>
92  string(5) "lemon"
93  ["o"]=>
94  string(6) "orange"
95}
96
97-- Testing asort() by supplying numeric array, 'flag' = SORT_REGULAR --
98bool(true)
99array(4) {
100  [4]=>
101  int(22)
102  [2]=>
103  int(33)
104  [1]=>
105  int(100)
106  [3]=>
107  int(555)
108}
109
110-- Testing asort() by supplying string array, 'flag' = SORT_STRING --
111bool(true)
112array(3) {
113  ["b"]=>
114  string(6) "banana"
115  ["l"]=>
116  string(5) "lemon"
117  ["o"]=>
118  string(6) "orange"
119}
120
121-- Testing asort() by supplying numeric array, 'flag' = SORT_NUMERIC --
122bool(true)
123array(4) {
124  [4]=>
125  int(22)
126  [2]=>
127  int(33)
128  [1]=>
129  int(100)
130  [3]=>
131  int(555)
132}
133Done
134