1function array_replace_key($search, $replace, array $subject) {
2 $updatedArray = [];
3
4 foreach ($subject as $key => $value) {
5 if (!is_array($value) && $key == $search) {
6 $updatedArray = array_merge($updatedArray, [$replace => $value]);
7
8 continue;
9 }
10
11 $updatedArray = array_merge($updatedArray, [$key => $value]);
12 }
13
14 return $updatedArray;
15}
16
17$user = ['name' => 'Donald Pakkies', 'age' => 22];
18
19var_dump(array_replace_key('name', 'full_name', $user));
20