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
.
More Related Contents:
- Split a comma-delimited string into an array?
- Return single column from a multi-dimensional array
- Convert backslash-delimited string into an associative array
- Convert a comma-delimited string into array of integers?
- Convert flat array to a delimited string to be saved in the database
- Implode a column of values from a two dimensional array [duplicate]
- Transpose 2d array, join second level with commas, and join first level with pipes
- php implode (101) with quotes
- Unexpected bracket ‘[‘ – PHP [duplicate]
- PHP: Split string into array, like explode with no delimiter
- Explode string into array with no empty elements?
- Native function to filter array by prefix
- How to implode array with key and value without foreach in PHP
- Split a string with two delimiters into two arrays (explode twice)
- Is there an equivalent in C++ of PHP’s explode() function? [duplicate]
- How to search by key=>value in a multidimensional array in PHP
- How to check if PHP array is associative or sequential?
- What is the best way to loop through this array in PHP?
- mysqli bind_param() expected to be a reference, value given
- Convert array into csv
- Get difference between associative rows of two 2-dimensional arrays
- How to find array / dictionary value using key?
- PHP object like array
- Flip associative array and store new values in subarrays to prevent losing duplicated values
- Get the maximum value from an element in a multidimensional array? [duplicate]
- Move an array element to a new index in PHP
- PHP get all arguments as array?
- Convert PHP array string into an array
- Sort a multidimensional array descending by subarray count and preserve first level keys
- Why does PHP not complain when I treat a null value as an array like this?