$arr1 is not populated with the most ideal values, so using more performant processes will take additional preparation.
To avoid preparatory processes on $arr1, make looped calls of preg_grep() and merge the results.
Code: (Demo)
var_export(
array_merge(
...array_map(fn($pattern) => preg_grep($pattern, $arr2), $arr1)
)
);
If you only had an array of literal needles, then you could make iterated str_starts_with() calls inside of array_filter(). (Demo)
$leadingNeedles = ['under', 'develop', 'repons'];
$arr2 = ['understand','underconstruction','developer','develope','hide','here','some'];
var_export(
array_filter(
$arr2,
function ($v) use ($leadingNeedles) {
foreach ($leadingNeedles as $needle) {
if (str_starts_with($v, $needle)) {
return true;
}
}
return false;
}
)
);
If you merely removed your pattern delimiters, you could implode the array of regex patterns with pipes and wrap then entire string in pattern delimiters, then preg_grep() is all you need. (Demo)
$regexes = ['^under.*', '^develop.*', '^repons.*'];
$arr2 = ['understand','underconstruction','developer','develope','hide','here','some'];
var_export(
preg_grep('/' . implode('|', $regexes) . '/', $arr2)
);
$arr1be an array? You can combine those patterns into one/^(under|develop|repons).*/but perhaps you have other more complex patterns. Actually, no regex is needed because they're all just the start of the string.strpos()would be fine.preg_grepfor example