RosettaCodeData/Task/Largest-int-from-concatenated-ints/PHP/largest-int-from-concatenated-ints.php
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

7 lines
230 B
PHP

function maxnum($nums) {
usort($nums, function ($x, $y) { return strcmp("$y$x", "$x$y"); });
return implode('', $nums);
}
echo maxnum(array(1, 34, 3, 98, 9, 76, 45, 4)), "\n";
echo maxnum(array(54, 546, 548, 60)), "\n";