- substr: documentation ( source)
- in_array: documentation ( source)
<?php
$strings = [
"ABwerty45^&*jk",
"ABwerrtty",
"LF%$^erftgt5234",
"TABYR56H",
"ab7877",
"Abtyu7"
];
$arr = ['AB', 'DC', 'LF'];
foreach ($strings as $string) {
$match = in_array(substr($string, 0, 2), $arr);
echo $match ? "Match: $string" . PHP_EOL : "No match: $string" . PHP_EOL;
}