1--TEST-- 2Test uasort() function : usage variations - sort diff. strings 3--FILE-- 4<?php 5/* 6* sorting different strings: 7* single quoted, double quoted and heredoc strings 8*/ 9 10// comparison function 11function cmp_function($value1, $value2) 12{ 13 if($value1 == $value2) { 14 return 0; 15 } 16 else if($value1 > $value2) { 17 return 1; 18 } 19 else { 20 return -1; 21 } 22} 23 24// Different heredoc strings to be sorted 25$empty_heredoc =<<<EOT 26EOT; 27 28$simple_heredoc1 =<<<EOT 29Heredoc 30EOT; 31 32$simple_heredoc2 =<<<EOT 33HEREDOC 34EOT; 35 36$multiline_heredoc =<<<EOT 37heredoc string\twith!@# and 123 38Test this!!! 39EOT; 40 41 42echo "*** Testing uasort() : different string arrays as 'array_arg' ***\n"; 43 44// Single quoted strings 45$single_quoted_values = array( 46 0 => ' ', 1 => 'test', 3 => 'Hello', 4 => 'HELLO', 47 5 => '', 6 => '\t', 7 => '0', 8 => '123Hello', 9 => '\'', 10 => '@#$%' 48); 49echo "-- Sorting Single Quoted String values --\n"; 50var_dump( uasort($single_quoted_values, 'cmp_function') ); // expecting: bool(true) 51var_dump($single_quoted_values); 52 53// Double quoted strings 54$double_quoted_values = array( 55 0 => " ", 1 => "test", 3 => "Hello", 4 => "HELLO", 56 5 => "", 6 => "\t", 7 => "0", 8 => "123Hello", 9 => "\"", 10 => "@#$%" 57); 58echo "-- Sorting Double Quoted String values --\n"; 59var_dump( uasort($double_quoted_values, 'cmp_function') ); // expecting: bool(true) 60var_dump($double_quoted_values); 61 62// Heredoc strings 63$heredoc_values = array(0 => $empty_heredoc, 1 => $simple_heredoc1, 2 => $simple_heredoc2, 3 => $multiline_heredoc); 64echo "-- Sorting Heredoc String values --\n"; 65var_dump( uasort($heredoc_values, 'cmp_function') ); // expecting: bool(true) 66var_dump($heredoc_values); 67 68echo "Done" 69?> 70--EXPECTF-- 71*** Testing uasort() : different string arrays as 'array_arg' *** 72-- Sorting Single Quoted String values -- 73bool(true) 74array(10) { 75 [5]=> 76 string(0) "" 77 [0]=> 78 string(1) " " 79 [9]=> 80 string(1) "'" 81 [7]=> 82 string(1) "0" 83 [8]=> 84 string(8) "123Hello" 85 [10]=> 86 string(4) "@#$%" 87 [4]=> 88 string(5) "HELLO" 89 [3]=> 90 string(5) "Hello" 91 [6]=> 92 string(2) "\t" 93 [1]=> 94 string(4) "test" 95} 96-- Sorting Double Quoted String values -- 97bool(true) 98array(10) { 99 [5]=> 100 string(0) "" 101 [6]=> 102 string(1) " " 103 [0]=> 104 string(1) " " 105 [9]=> 106 string(1) """ 107 [7]=> 108 string(1) "0" 109 [8]=> 110 string(8) "123Hello" 111 [10]=> 112 string(4) "@#$%" 113 [4]=> 114 string(5) "HELLO" 115 [3]=> 116 string(5) "Hello" 117 [1]=> 118 string(4) "test" 119} 120-- Sorting Heredoc String values -- 121bool(true) 122array(4) { 123 [0]=> 124 string(0) "" 125 [2]=> 126 string(7) "HEREDOC" 127 [1]=> 128 string(7) "Heredoc" 129 [3]=> 130 string(4%d) "heredoc string with!@# and 123 131Test this!!!" 132} 133Done 134