Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
format the code
Source Link
Manoj Sharma
  • 1.5k
  • 2
  • 13
  • 20

Here is a helper function to achieve that:

/** * Helper function to rename array keys. */ function _rename_arr_key($oldkey, $newkey, array &$arr) {   if (array_key_exists($oldkey, $arr)) {   $arr[$newkey] = $arr[$oldkey];   unset($arr[$oldkey]);   return TRUE;   } else {   return FALSE;   } } 

pretty based on [@KernelM answer][1].

Usage:

_rename_arr_key('oldkey', 'newkey', $my_array); 

It will return true on successful rename, otherwise false. [1]: https://stackoverflow.com/a/240676/55075

Here is a helper function to achieve that:

/** * Helper function to rename array keys. */ function _rename_arr_key($oldkey, $newkey, array &$arr) { if (array_key_exists($oldkey, $arr)) { $arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]); return TRUE; } else { return FALSE; } } 

pretty based on [@KernelM answer][1].

Usage:

_rename_arr_key('oldkey', 'newkey', $my_array); 

It will return true on successful rename, otherwise false. [1]: https://stackoverflow.com/a/240676/55075

Here is a helper function to achieve that:

/** * Helper function to rename array keys. */ function _rename_arr_key($oldkey, $newkey, array &$arr) {   if (array_key_exists($oldkey, $arr)) {   $arr[$newkey] = $arr[$oldkey];   unset($arr[$oldkey]);   return TRUE;   } else {   return FALSE;   } } 

pretty based on [@KernelM answer][1].

Usage:

_rename_arr_key('oldkey', 'newkey', $my_array); 

It will return true on successful rename, otherwise false. [1]: https://stackoverflow.com/a/240676/55075

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Here is a helper function to achieve that:

/** * Helper function to rename array keys. */ function _rename_arr_key($oldkey, $newkey, array &$arr) { if (array_key_exists($oldkey, $arr)) { $arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]); return TRUE; } else { return FALSE; } } 

pretty based on [@KernelM answer][1].

Usage:

_rename_arr_key('oldkey', 'newkey', $my_array); 

It will return true on successful rename, otherwise false. [1]: http://stackoverflow.com/a/240676/55075https://stackoverflow.com/a/240676/55075

Here is a helper function to achieve that:

/** * Helper function to rename array keys. */ function _rename_arr_key($oldkey, $newkey, array &$arr) { if (array_key_exists($oldkey, $arr)) { $arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]); return TRUE; } else { return FALSE; } } 

pretty based on [@KernelM answer][1].

Usage:

_rename_arr_key('oldkey', 'newkey', $my_array); 

It will return true on successful rename, otherwise false. [1]: http://stackoverflow.com/a/240676/55075

Here is a helper function to achieve that:

/** * Helper function to rename array keys. */ function _rename_arr_key($oldkey, $newkey, array &$arr) { if (array_key_exists($oldkey, $arr)) { $arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]); return TRUE; } else { return FALSE; } } 

pretty based on [@KernelM answer][1].

Usage:

_rename_arr_key('oldkey', 'newkey', $my_array); 

It will return true on successful rename, otherwise false. [1]: https://stackoverflow.com/a/240676/55075

Source Link
kenorb
  • 168.7k
  • 95
  • 712
  • 796

Here is a helper function to achieve that:

/** * Helper function to rename array keys. */ function _rename_arr_key($oldkey, $newkey, array &$arr) { if (array_key_exists($oldkey, $arr)) { $arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]); return TRUE; } else { return FALSE; } } 

pretty based on [@KernelM answer][1].

Usage:

_rename_arr_key('oldkey', 'newkey', $my_array); 

It will return true on successful rename, otherwise false. [1]: http://stackoverflow.com/a/240676/55075