1--TEST-- 2Test usort() function : usage variations - diff. array values 3--FILE-- 4<?php 5/* 6 * Pass an array with different data types as keys 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 25 26// single line heredoc string 27$simple_heredoc = <<<EOT2 28simple 29EOT2; 30 31// multiline heredoc string 32$multiline_heredoc = <<<EOT3 33multiline heredoc with 123 34and speci@! ch@r..\ncheck\talso 35EOT3; 36 37$array_arg = array( 38 // numeric keys 39 -2 => 9, 40 8 => 8, 41 012 => 7, 42 0x34 => 6, 43 44 // string keys 45 'key' => 5, //single quoted key 46 "two" => 4, //double quoted key 47 " " => 0, // space as key 48 49 // bool keys 50 TRUE => 100, 51 FALSE => 25, 52 53 // null keys 54 NULL => 35, 55 56 // binary key 57 "a".chr(0)."b" => 45, 58 b"binary" => 30, 59 60 //heredoc keys 61 $simple_heredoc => 75, 62 $multiline_heredoc => 200, 63 64 // default key 65 1, 66); 67 68var_dump( usort($array_arg, 'cmp_function') ); 69echo "\n-- Sorted array after usort() function call --\n"; 70var_dump($array_arg); 71?> 72--EXPECT-- 73*** Testing usort() : usage variation *** 74bool(true) 75 76-- Sorted array after usort() function call -- 77array(15) { 78 [0]=> 79 int(200) 80 [1]=> 81 int(100) 82 [2]=> 83 int(75) 84 [3]=> 85 int(45) 86 [4]=> 87 int(35) 88 [5]=> 89 int(30) 90 [6]=> 91 int(25) 92 [7]=> 93 int(9) 94 [8]=> 95 int(8) 96 [9]=> 97 int(7) 98 [10]=> 99 int(6) 100 [11]=> 101 int(5) 102 [12]=> 103 int(4) 104 [13]=> 105 int(1) 106 [14]=> 107 int(0) 108} 109