'i want to sort variables which contains numbers in PHP [closed]

I'm working on a project and what i want to do is to sort a variable which contains numbers..like 123546 etc..now I want to sort them like 123456 etc if it's in variable then its great, but if it's in array then also great.



Solution 1:[1]

This should take care of it, assuming all numbers are in fact singular.

$numbers = str_split('123546');

sort($numbers);

echo join('', $numbers);

Demo

It uses str_split() to turn the string into an array, the array is then sorted and then joined together.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ja͢ck