You can use usort
by string compare and the add prefix to each element with str_repeat
Consider:
$arr = array("10", "1001","12", "1201","1002", "1202","120101", "120201","13");
usort($arr, "strcasecmp"); // sorting the array by string and not array
function addPre($v) {
$mul = strlen($v) / 2; // check the string size and divided by 2 as your example
return str_repeat("\t", $mul - 1) . str_repeat("-", $mul) . $v;
}
foreach($arr as $e)
echo addPre($e) . PHP_EOL;
Reference: str-repeat, usort
solved How To Group and Sort Array element base Specific Character [closed]