- var_export: documentation ( source)
- str_split: documentation ( source)
<?php
$array = [];
$lastChar = null;
foreach (str_split('10001101') as $char) {
if ($char !== $lastChar) {
unset($ref);
$array[] = &$ref;
$ref = $char;
$lastChar = $char;
} else {
$ref .= $char;
}
}
var_export($array);