- array_map: documentation ( source)
- array_slice: documentation ( source)
- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$string1 = "-val1(sec1)-";
$string2 = "-val2(sec2)-";
$string3 = "-val3(sec3)-";
$big_string = $string1 . $string2 . $string3;
if (preg_match_all('/-([^(]+)\(([^)]+)\)-/', $big_string, $matches, PREG_SET_ORDER)) {
$result = array_map(static fn($match) => array_slice($match, 1), $matches);
print_r($result);
}