<?php
function sortString($str) {
if ($str != null) {
$arr = explode(" ", $str);
$arr2 = array();
foreach ($arr as $key => $value) {
preg_match('/[0-9]/', $value, $matches);
$arr2[$matches[0]] = $value;
}
ksort($arr2);
$newStr = implode(" ", $arr2);
return $newStr;
} else {
return "";
}
}
$str = "g5et ski3lls on6 use1 your2 to4 7top";
$res = sortString($str);
echo $res;
?>