3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function array_replace_key($search, $replace, array $target) { $return = array(); foreach ($target as $key => $val) { if ($search === $key && array_key_exists($replace, $target) === false) { $return[$replace] = $val; } else { $return[$key] = $val; } } return $return; } $a = array('a' => 'franz', 'b' => 'cheryl', 'c' => 'samantha'); var_dump(array_replace_key('a', 'b', $a));
Output for 5.3.0 - 7.1.0
array(3) { ["a"]=> string(5) "franz" ["b"]=> string(6) "cheryl" ["c"]=> string(8) "samantha" }