It is not needed to check all permutations. I think this can be solved in O(k.n.log(n)) time where n is the array size and k is the number of characters in the longest string.
The idea is that the strings should be sorted by padding them first so all have the same length. The padding should happen by repeating the original string after itself as many times as necessary and then clipped to a common length. When that length is taken to be the double length of the largest string then the result will be fine.
Take for instance this input:
["1", "1112", "11121", "111230", "385", "38530"]
Then the algorithm would extend those strings as follows:
["111111111111","111211121112","111211112111","111230111230","385385385385","385303853038"]
Sorted in descending order this gives:
["385385385385","385303853038","111230111230","111211121112","111211112111","111111111111"]
Converted back to their original values:
["385", "38530", "111230", "1112", "11121", "1"]
which gives the result:
"385385301112301112111211"
Here is the code for that:
$array = ["1", "1112", "11121", "111230", "385", "38530"];
$maxlen = 2 * max(array_map('strlen', $array));
$padded = array_map(function ($a) use ($maxlen) {
return substr(str_repeat($a, ceil($maxlen / strlen($a))), 0, $maxlen);
}, $array);
array_multisort($padded, SORT_DESC, $array);
$result = implode("", $array);
echo $result;
Unlike the accepted answer, this also works in reasonable time for arrays which have more than a few values:
See it run on eval.in for input:
["3", "1", "7", "8", "9", "2", "4", "6", "5", "0", "15", "29", "32", "41",
"551", "56", "671", "6713", "782", "7820", "88", "880", "91", "9121"]
It outputs:
991912188888078278207671671365655514413322921510