convert ***sort builtins to use inout instead of references
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / array / usort_variation5.php
blobb829b033437aa8cf1070f3558c3e533b2ba7693e
1 <?hh
2 /* Prototype : bool usort(&array $array_arg, string $cmp_function)
3 * Description: Sort an array by values using a user-defined comparison function
4 * Source code: ext/standard/array.c
5 */
7 /*
8 * Pass arrays of string data to usort() to test how it is re-ordered
9 */
11 function cmp_function($value1, $value2)
13 if($value1 == $value2) {
14 return 0;
16 else if($value1 > $value2) {
17 return 1;
19 else {
20 return -1;
23 <<__EntryPoint>> function main(): void {
24 echo "*** Testing usort() : usage variation ***\n";
26 // Different heredoc strings to be sorted
27 $empty_heredoc =<<<EOT
28 EOT;
30 $simple_heredoc1 =<<<EOT
31 Heredoc
32 EOT;
34 $simple_heredoc2 =<<<EOT
35 HEREDOC
36 EOT;
38 $multiline_heredoc =<<<EOT
39 heredoc string\twith!@# and 123
40 Test this!!!
41 EOT;
43 // Single quoted strings
44 $single_quoted_values = array(
45 0 => ' ', 1 => 'test', 3 => 'Hello', 4 => 'HELLO',
46 5 => '', 6 => '\t', 7 => '0', 8 => '123Hello',
47 9 => '\'', 10 => '@#$%'
50 echo "\n-- Sorting Single Quoted String values --\n";
51 var_dump( usort(inout $single_quoted_values, fun('cmp_function')) );
52 var_dump($single_quoted_values);
54 // Double quoted strings
55 $double_quoted_values = array(
56 0 => " ", 1 => "test", 3 => "Hello", 4 => "HELLO",
57 5 => "", 6 => "\t", 7 => "0", 8 => "123Hello",
58 9 => "\"", 10 => "@#$%"
61 echo "\n-- Sorting Double Quoted String values --\n";
62 var_dump( usort(inout $double_quoted_values, fun('cmp_function')) );
63 var_dump($double_quoted_values);
65 // Heredoc strings
66 $heredoc_values = array(0 => $empty_heredoc, 1 => $simple_heredoc1,
67 2 => $simple_heredoc2, 3 => $multiline_heredoc);
69 echo "\n-- Sorting Heredoc String values --\n";
70 var_dump( usort(inout $heredoc_values, fun('cmp_function')) );
71 var_dump($heredoc_values);
72 echo "===DONE===\n";