3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_flip_keys($array, $x, $y) { if(array_key_exists($x, $array) && array_key_exists($y, $array)) { $result = []; foreach($array as $key=>$value) { switch($key) { case $x: $result[$y]=$array[$y]; continue; case $y: $result[$x]=$array[$x]; continue; default: $result[$key]=$value; } } return $result; } return $array; } $array = ['foo', 'bar', 'baz', 'feo']; var_dump(array_flip_keys($array, 3, 0));
Output for git.master, git.master_jit, rfc.property-hooks
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /in/7hI0m on line 14 Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /in/7hI0m on line 17 array(4) { [3]=> string(3) "feo" [1]=> string(3) "bar" [2]=> string(3) "baz" [0]=> string(3) "foo" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.92 ms | 402 KiB | 8 Q