Created
March 23, 2021 05:35
-
-
Save gnanasekaran08/e6a5bff1c67f4fcca7541248d8c88ff6 to your computer and use it in GitHub Desktop.
change key from array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$option = change_key($args,'id','name'); | |
function change_key($array, $old_key, $new_key) | |
{ | |
if (!array_key_exists($old_key, $array)) { | |
return $array; | |
} | |
$keys = array_keys($array); | |
$keys[array_search($old_key, $keys)] = $new_key; | |
return array_combine($keys, $array); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment