<?php
$s = "12345";
$res = [];
if (preg_match_all('~(?=((\d)\d?))~', $s, $m, PREG_SET_ORDER)) {
$single = []; $double = [];
foreach ($m as $v) {
if ($v[1] != $v[2]) {
array_push($single, $v[2]);
array_push($double, $v[1]);
} else {
array_push($single, $v[1]);
}
}
$res = array_merge($single, $double);
print_r( $res );
}
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 12
[6] => 23
[7] => 34
[8] => 45
)
preferences:
121.15 ms | 402 KiB | 121 Q