Add a prefix to each item of a PHP array

An elegant way to prefix array values (PHP 5.3+):

$prefixed_array = preg_filter('/^/', 'prefix_', $array);

Additionally, this is more than three times faster than a foreach.

Leave a Comment