Iterate the array, add a new element with the changed key and delete the original element:
foreach ($arr as $key => $val) {
$arr['r_'.$key] = $val;
unset($arr[$key]);
}
Since it foreachworks with an internal copy of an array, you are not starting an infinite loop.
Gumbo source
share