1--TEST-- 2Test usort() function : usage variations - duplicate keys and values 3--FILE-- 4<?php 5/* 6 * Pass an array with duplicate keys and values to usort() to test behaviour 7 */ 8 9echo "*** Testing usort() : usage variation ***\n"; 10 11function cmp($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// Array with duplicate string and integer keys and values 24$array_arg = array(0 => 2, "a" => 8, "d" => 9, 25 3 => 3, 5 => 2, "o" => 6, 26 "z" => -99, 0 => 1, "z" => 3); 27 28echo "\n-- Array with duplicate keys --\n"; 29var_dump( usort($array_arg, 'cmp') ); 30var_dump($array_arg); 31 32// Array with default and assigned keys 33$array_arg = array(0 => "Banana", 1 => "Mango", "Orange", 2 => "Apple", "Pineapple"); 34 35echo "\n-- Array with default/assigned keys --\n"; 36var_dump( usort($array_arg, 'cmp') ); 37var_dump($array_arg); 38?> 39--EXPECT-- 40*** Testing usort() : usage variation *** 41 42-- Array with duplicate keys -- 43bool(true) 44array(7) { 45 [0]=> 46 int(1) 47 [1]=> 48 int(2) 49 [2]=> 50 int(3) 51 [3]=> 52 int(3) 53 [4]=> 54 int(6) 55 [5]=> 56 int(8) 57 [6]=> 58 int(9) 59} 60 61-- Array with default/assigned keys -- 62bool(true) 63array(4) { 64 [0]=> 65 string(5) "Apple" 66 [1]=> 67 string(6) "Banana" 68 [2]=> 69 string(5) "Mango" 70 [3]=> 71 string(9) "Pineapple" 72} 73