I have a big associative array with over 1 000 items and I want to rename one key but the order must be preserved.
I don't wont to iterate over the complete array and copy it into a new.
I have a big associative array with over 1 000 items and I want to rename one key but the order must be preserved.
I don't wont to iterate over the complete array and copy it into a new.
 
    
     
    
    have a look at the array_splice function: http://php.net/manual/en/function.array-splice.php
this will do the job
 
    
      $array_keys = array_keys($array);
  $array_keys[array_search('old', $array_keys)] = 'new';
  $array = array_combine($array_keys, $array);
 
    
    $array[$newkeyname] = $array[$oldkeyname];
unset($array[$oldkeyname]);
