3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function array_replace_key($search, $replace, array $target) { $return = array(); foreach ($target as $key => $val) { if ($search === $key) { $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 - 5.6.30, hhvm-3.10.1 - 3.17.3, 7.0.0 - 7.1.7
array(2) { ["b"]=> string(6) "cheryl" ["c"]=> string(8) "samantha" }