convert ***sort builtins to use inout instead of references
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / array / ksort_basic.php
blobc1cad86722e0c3533cc9820615a8f93d75bb7fa4
1 <?hh
2 /* Prototype : bool ksort ( array &$array [, int $sort_flags] )
3 * Description: Sort an array by key, maintaining key to data correlation
4 * Source code: ext/standard/array.c
5 */
7 /*
8 * Testing ksort() by providing array of integer/string values to check the basic functionality with following flag values :
9 * 1.flag value as defualt
10 * 2.SORT_REGULAR - compare items normally
11 * 3.SORT_NUMERIC - compare items numerically
12 * 4.SORT_STRING - compare items as strings
14 <<__EntryPoint>> function main(): void {
15 echo "*** Testing ksort() : basic functionality ***\n";
17 // an array containing unsorted string values with indices
18 $unsorted_strings = array(
19 "l" => "lemon", "o" => "orange",
20 "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20",
21 "b" => "banana",
23 // an array containing unsorted numeric values with indices
24 $unsorted_numerics = array( 100 => 4, 33 => 3, 555 => 2, 22 => 1 );
26 echo "\n-- Testing ksort() by supplying string array, 'flag' value is defualt --\n";
27 $temp_array = $unsorted_strings;
28 var_dump( ksort(inout $temp_array) ); // expecting : bool(true)
29 var_dump( $temp_array);
31 echo "\n-- Testing ksort() by supplying numeric array, 'flag' value is defualt --\n";
32 $temp_array = $unsorted_numerics;
33 var_dump( ksort(inout $temp_array) ); // expecting : bool(true)
34 var_dump( $temp_array);
36 echo "\n-- Testing ksort() by supplying string array, 'flag' = SORT_REGULAR --\n";
37 $temp_array = $unsorted_strings;
38 var_dump( ksort(inout $temp_array, SORT_REGULAR) ); // expecting : bool(true)
39 var_dump( $temp_array);
41 echo "\n-- Testing ksort() by supplying numeric array, 'flag' = SORT_REGULAR --\n";
42 $temp_array = $unsorted_numerics;
43 var_dump( ksort(inout $temp_array, SORT_REGULAR) ); // expecting : bool(true)
44 var_dump( $temp_array);
46 echo "\n-- Testing ksort() by supplying string array, 'flag' = SORT_STRING --\n";
47 $temp_array = $unsorted_strings;
48 var_dump( ksort(inout $temp_array, SORT_STRING) ); // expecting : bool(true)
49 var_dump( $temp_array);
51 echo "\n-- Testing ksort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n";
52 $temp_array = $unsorted_strings;
53 var_dump( sort(inout $temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true)
54 var_dump( $temp_array);
56 echo "\n-- Testing ksort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n";
57 $temp_array = $unsorted_strings;
58 var_dump( sort(inout $temp_array, SORT_NATURAL) ); // expecting : bool(true)
59 var_dump( $temp_array);
61 echo "\n-- Testing ksort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n";
62 $temp_array = $unsorted_strings;
63 var_dump( sort(inout $temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true)
64 var_dump( $temp_array);
66 echo "\n-- Testing ksort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n";
67 $temp_array = $unsorted_numerics;
68 var_dump( ksort(inout $temp_array, SORT_NUMERIC) ); // expecting : bool(true)
69 var_dump( $temp_array);
71 echo "Done\n";