If you're worried about performance, don't go doing trivial operations with regular expressions, they're inherently slow. Apart from that, since you're actively modifying keys, there's no other way than reconstructing a new array:
$params = [];
foreach($array as $key => $value)
$params[substr($key, 5)] = $value;
In this code substr($key, 5)
just strips the leading user_
part of each key and rebuilds the $params
array to what you need. I'd be highly surprised if there was a faster solution.
If you actually want to check for data integrity and only extract the properly prefixed keys the problem becomes more complex:
function extractPrefixedElements(array $array, $prefix)
{
$result = [];
foreach($array as $key => $value)
{
list($pre, $newKey) = explode('_', $key, 2);
if($pre == $prefix)
$result[$newKey] = $value;
}
return $result;
}
extractPrefixedElements($array, 'user');