3v4l.org

run code in 300+ PHP versions simultaneously
<?php $stringRegex = "/([aA][0-9]+)/"; $schema = [ 'a26UserId', 'a17Passwd', 'cAccountChannel', 'a256PcInfo1' ]; $result = []; foreach ($schema as $currentType) { if (preg_match($stringRegex, $currentType, $matches)) { $result[] = $matches[1]; } else { $result[] = substr($currentType, 0, 1); } } print_r($result);

preferences:
46.61 ms | 402 KiB | 5 Q