Just that you would have to link back to the original - ie search the keys to make one with just the keys/values that met what they originally wanted:
That is precisely what the code is supposed to do. In fact, your own code does a linear search of the array keys.
EDIT:
Okay, I don't really want to spoonfeed the OP here, but this is what I had in mind:
<?php
$array = array(
'a' => 1,
'ab' => 2,
'-a' => 3,
'-a_' => 4,
'a-' => 5,
'-ab' => 6,
'_ab-' => 7,
'ab_' => 8,
'abc123' => 9,
'abc123_' => 10,
'_-' => 11
);
$result = array();
foreach (array_keys($array) as $key) {
if (preg_match('/^[a-z_-]*([a-z][_-]|[_-][a-z])[a-z_-]*$/i', $key)) {
$result[$key] = $array[$key];
}
}
print_r($result);
?>
I regard this solution as straightforward: it is easy to see that the keys are being processed.