Skip to content

Instantly share code, notes, and snippets.

@egfx
Created August 5, 2011 23:37
Show Gist options
  • Save egfx/7cc8d3f8b91c4a5efd9b to your computer and use it in GitHub Desktop.
Save egfx/7cc8d3f8b91c4a5efd9b to your computer and use it in GitHub Desktop.
Replace a key in an associative array, preserving the original order of keys and elements:
<?php
if (!function_exists('array_combine')) { // ONLY EXISTS IN PHP5
function array_combine($keys, $values) {
if (count($keys) != count($values)) {
return false; }
foreach($keys as $key) { $array[$key] = array_shift($values); }
return $array; }
} // END IF FUNCTION EXISTS
$keys = array_keys($array);
$values = array_values($array);
foreach ($keys as $k => $v) {
if ($v == "MANAGEMENT FEE CHARGE") { $keys[$k] = "MANAGEMENT FEES"; }
}
$array = array_combine($keys, $values);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment