preg_match_all() provides a direct, single-function technique without looping.
Capture the digits ($out[1]) and store the letters in the fullstring match ($out[0]). No unnecessary subarrays in $out.
Code: (Demo)
$string = "1A1R0A";
var_export(preg_match_all('~(\d)\K\D~', $string, $out) ? [$out[1], $out[0]] : [[], []]);
echo "\n--- or ---\n";
[$letters, $numbers] = preg_match_all('~(\d)\K\D~', $string, $out) ? $out : [[], []];
var_export($numbers);
echo "\n";
var_export($letters);
Output:
array (
0 =>
array (
0 => '1',
1 => '1',
2 => '0',
),
1 =>
array (
0 => 'A',
1 => 'R',
2 => 'A',
),
)
--- or ---
array (
0 => '1',
1 => '1',
2 => '0',
)
array (
0 => 'A',
1 => 'R',
2 => 'A',
)
If your string may start with a letter or your letter-number sequence is not guaranteed to alternate, you can use this direct technique to separate the two character categories.
Code: (Demo)
$string = "B1A23R4CD";
$output = [[], []]; // ensures that the numbers array comes first
foreach (str_split($string) as $char) {
$output[ctype_alpha($char)][] = $char;
// ^^^^^^^^^^^^^^^^^^- false is 0, true is 1
}
var_export($output);
Output:
array (
0 =>
array (
0 => '1',
1 => '2',
2 => '3',
3 => '4',
),
1 =>
array (
0 => 'B',
1 => 'A',
2 => 'R',
3 => 'C',
4 => 'D',
),
)