3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = ['a' => 'val1', 'b' => 'val2', 'c' => 'val3', 'd' => 'val4', 'e' => 'val5']; $swaps = ['a' => 'd', 'd' => 'a'/*, 'b' => 'e', 'e' => 'b'*/]; $result = []; foreach ($array as $k => $v) { if (!isset($swaps[$k], $array[$swaps[$k]])) { $result[$k] = $v; } else { $result[$swaps[$k]] = $array[$swaps[$k]]; } } var_export($result);
Output for git.master_jit, git.master
array ( 'd' => 'val4', 'b' => 'val2', 'c' => 'val3', 'a' => 'val1', 'e' => 'val5', )

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:
52.87 ms | 405 KiB | 5 Q