1--TEST-- 2Test uasort() function : usage variations - sort array with all possible keys 3--FILE-- 4<?php 5/* 6* Testing uasort() with 'array_arg' having different keys 7*/ 8 9echo "*** Testing uasort() : Sorting array with all possible keys ***\n"; 10 11//comparison function 12function cmp_function($value1, $value2) 13{ 14 if($value1 == $value2) { 15 return 0; 16 } 17 else if($value1 > $value2) { 18 return -1; 19 } 20 else { 21 return 1; 22 } 23} 24 25// different heredoc strings 26//empty heredoc string 27$empty_heredoc = <<<EOT1 28EOT1; 29 30// single line heredoc string 31$simple_heredoc = <<<EOT2 32simple 33EOT2; 34 35// multiline heredoc string 36$multiline_heredoc = <<<EOT3 37multiline heredoc with 123 38and speci@! ch@r..\ncheck\talso 39EOT3; 40 41$array_arg = array( 42 // default key 43 1, //expecting: default key 0, value will be replaced by 'FALSE' 44 45 // numeric keys 46 1 => 10, // expecting: value will be replaced by 'TRUE' 47 -2 => 9, 48 8.9 => 8, 49 012 => 7, 50 0x34 => 6, 51 52 // string keys 53 'key' => 5, //single quoted key 54 "two" => 4, //double quoted key 55 '' => 3, 56 "" => 2, 57 " " => 0, // space as key 58 59 // bool keys 60 true => 15, 61 false => 5, 62 TRUE => 100, 63 FALSE => 25, 64 65 // null keys 66 null => 20, // expecting: value will be replaced by 'NULL' 67 NULL => 35, 68 69 // binary key 70 "a".chr(0)."b" => 45, 71 b"binary" => 30, 72 73 //heredoc keys 74 $empty_heredoc => 90, 75 $simple_heredoc => 75, 76 $multiline_heredoc => 200, 77); 78 79var_dump( uasort($array_arg, 'cmp_function') ); 80echo "-- Sorted array after uasort() function call --\n"; 81var_dump($array_arg); 82 83echo "Done" 84?> 85--EXPECT-- 86*** Testing uasort() : Sorting array with all possible keys *** 87bool(true) 88-- Sorted array after uasort() function call -- 89array(14) { 90 ["multiline heredoc with 123 91and speci@! ch@r.. 92check also"]=> 93 int(200) 94 [1]=> 95 int(100) 96 [""]=> 97 int(90) 98 ["simple"]=> 99 int(75) 100 ["ab"]=> 101 int(45) 102 ["binary"]=> 103 int(30) 104 [0]=> 105 int(25) 106 [-2]=> 107 int(9) 108 [8]=> 109 int(8) 110 [10]=> 111 int(7) 112 [52]=> 113 int(6) 114 ["key"]=> 115 int(5) 116 ["two"]=> 117 int(4) 118 [" "]=> 119 int(0) 120} 121Done 122