1--TEST-- 2Test usort() function : usage variations - string data 3--FILE-- 4<?php 5/* 6 * Pass arrays of string data to usort() to test how it is re-ordered 7 */ 8 9echo "*** Testing usort() : usage variation ***\n"; 10 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// Single quoted strings 42$single_quoted_values = array( 43 0 => ' ', 1 => 'test', 3 => 'Hello', 4 => 'HELLO', 44 5 => '', 6 => '\t', 7 => '0', 8 => '123Hello', 45 9 => '\'', 10 => '@#$%' 46); 47 48echo "\n-- Sorting Single Quoted String values --\n"; 49var_dump( usort($single_quoted_values, 'cmp_function') ); 50var_dump($single_quoted_values); 51 52// Double quoted strings 53$double_quoted_values = array( 54 0 => " ", 1 => "test", 3 => "Hello", 4 => "HELLO", 55 5 => "", 6 => "\t", 7 => "0", 8 => "123Hello", 56 9 => "\"", 10 => "@#$%" 57); 58 59echo "\n-- Sorting Double Quoted String values --\n"; 60var_dump( usort($double_quoted_values, 'cmp_function') ); 61var_dump($double_quoted_values); 62 63// Heredoc strings 64$heredoc_values = array(0 => $empty_heredoc, 1 => $simple_heredoc1, 65 2 => $simple_heredoc2, 3 => $multiline_heredoc); 66 67echo "\n-- Sorting Heredoc String values --\n"; 68var_dump( usort($heredoc_values, 'cmp_function') ); 69var_dump($heredoc_values); 70?> 71--EXPECTF-- 72*** Testing usort() : usage variation *** 73 74-- Sorting Single Quoted String values -- 75bool(true) 76array(10) { 77 [0]=> 78 string(0) "" 79 [1]=> 80 string(1) " " 81 [2]=> 82 string(1) "'" 83 [3]=> 84 string(1) "0" 85 [4]=> 86 string(8) "123Hello" 87 [5]=> 88 string(4) "@#$%" 89 [6]=> 90 string(5) "HELLO" 91 [7]=> 92 string(5) "Hello" 93 [8]=> 94 string(2) "\t" 95 [9]=> 96 string(4) "test" 97} 98 99-- Sorting Double Quoted String values -- 100bool(true) 101array(10) { 102 [0]=> 103 string(0) "" 104 [1]=> 105 string(1) " " 106 [2]=> 107 string(1) " " 108 [3]=> 109 string(1) """ 110 [4]=> 111 string(1) "0" 112 [5]=> 113 string(8) "123Hello" 114 [6]=> 115 string(4) "@#$%" 116 [7]=> 117 string(5) "HELLO" 118 [8]=> 119 string(5) "Hello" 120 [9]=> 121 string(4) "test" 122} 123 124-- Sorting Heredoc String values -- 125bool(true) 126array(4) { 127 [0]=> 128 string(0) "" 129 [1]=> 130 string(7) "HEREDOC" 131 [2]=> 132 string(7) "Heredoc" 133 [3]=> 134 string(%d) "heredoc string with!@# and 123 135Test this!!!" 136} 137