I have this PHP snippet:
<?php
$colors = array('red','green','blue');
foreach ($colors as &$item)
{
$item = 'color-'.$item;
}
print_r($colors);
?>
Output:
Array
(
[0] => color-red
[1] => color-green
[2] => color-blue
)
Is it simpler solution ?
(some array php function like that array_insert_before_all_items($colors,"color-"))?
Thanks
The method array_walk will let you ‘visit’ each item in the array with a callback. With php 5.3 you can even use anonymous functions
Pre PHP 5.3 version:
Newer anonymous function version: