convert ***sort builtins to use inout instead of references
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / array / rsort_basic.php
blob8b48e4119a42e82f8b9af630f0bf1d0d6ae008e6
1 <?hh
2 /* Prototype : bool rsort(array &$array_arg [, int $sort_flags])
3 * Description: Sort an array in reverse order
4 * Source code: ext/standard/array.c
5 */
7 /*
8 * Test basic functionality of rsort()
9 */
10 <<__EntryPoint>> function main(): void {
11 echo "*** Testing rsort() : basic functionality ***\n";
13 // associative array containing unsorted string values
14 $unsorted_strings = array(
15 "l" => "lemon", "o" => "orange",
16 "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20",
17 "b" => "banana",
20 // array with default keys containing unsorted numeric values
21 $unsorted_numerics = array( 100, 33, 555, 22 );
23 echo "\n-- Testing rsort() by supplying string array, 'flag' value is defualt --\n";
24 $temp_array = $unsorted_strings;
25 var_dump( rsort(inout $temp_array) );
26 var_dump( $temp_array);
28 echo "\n-- Testing rsort() by supplying numeric array, 'flag' value is defualt --\n";
29 $temp_array = $unsorted_numerics;
30 var_dump( rsort(inout $temp_array) );
31 var_dump( $temp_array);
33 echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR --\n";
34 $temp_array = $unsorted_strings;
35 var_dump( rsort(inout $temp_array, SORT_REGULAR) );
36 var_dump( $temp_array);
38 echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n";
39 $temp_array = $unsorted_numerics;
40 var_dump( rsort(inout $temp_array, SORT_REGULAR) );
41 var_dump( $temp_array);
43 echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_STRING --\n";
44 $temp_array = $unsorted_strings;
45 var_dump( rsort(inout $temp_array, SORT_STRING) );
46 var_dump( $temp_array);
48 echo "\n-- Testing rsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n";
49 $temp_array = $unsorted_strings;
50 var_dump( rsort(inout $temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true)
51 var_dump( $temp_array);
53 echo "\n-- Testing rsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n";
54 $temp_array = $unsorted_strings;
55 var_dump( rsort(inout $temp_array, SORT_NATURAL) ); // expecting : bool(true)
56 var_dump( $temp_array);
58 echo "\n-- Testing rsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n";
59 $temp_array = $unsorted_strings;
60 var_dump( rsort(inout $temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true)
61 var_dump( $temp_array);
63 echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
64 $temp_array = $unsorted_numerics;
65 var_dump( rsort(inout $temp_array, SORT_NUMERIC) );
66 var_dump( $temp_array);
68 echo "Done";