uasort_variation3.phpt [plain text]
--TEST--
Test uasort() function : usage variations - sort array with all posible keys
--FILE--
<?php
echo "*** Testing uasort() : Sorting array with all possible keys ***\n";
function cmp_function($value1, $value2)
{
if($value1 == $value2) {
return 0;
}
else if($value1 > $value2) {
return -1;
}
else {
return 1;
}
}
$empty_heredoc = <<<EOT1
EOT1;
$simple_heredoc = <<<EOT2
simple
EOT2;
$multiline_heredoc = <<<EOT3
multiline heredoc with 123
and speci@! ch@r..\ncheck\talso
EOT3;
$array_arg = array(
1,
1 => 10, -2 => 9,
8.9 => 8,
012 => 7,
0x34 => 6,
'key' => 5, "two" => 4, '' => 3,
"" => 2,
" " => 0,
true => 15,
false => 5,
TRUE => 100,
FALSE => 25,
null => 20, NULL => 35,
"a".chr(0)."b" => 45,
b"binary" => 30,
$empty_heredoc => 90,
$simple_heredoc => 75,
$multiline_heredoc => 200,
);
var_dump( uasort($array_arg, 'cmp_function') );
echo "-- Sorted array after uasort() function call --\n";
var_dump($array_arg);
echo "Done"
?>
--EXPECTF--
*** Testing uasort() : Sorting array with all possible keys ***
bool(true)
-- Sorted array after uasort() function call --
array(14) {
["multiline heredoc with 123
and speci@! ch@r..
check also"]=>
int(200)
[1]=>
int(100)
[""]=>
int(90)
["simple"]=>
int(75)
["a b"]=>
int(45)
["binary"]=>
int(30)
[0]=>
int(25)
[-2]=>
int(9)
[8]=>
int(8)
[10]=>
int(7)
[52]=>
int(6)
["key"]=>
int(5)
["two"]=>
int(4)
[" "]=>
int(0)
}
Done