3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = array( 'a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h', 'i' => 'j', 'k' => 'l', ); $replacement = array( 'w' => 'x', 'y' => 'z' ); $offset = -3; // illegal offset - MAGIC? $length = 2; if ($replacement === null) { // + operator with null causes FATAL ERROR! $replacement = array(); } if (empty($input)) { $input = $replacement; return; } // split array at $offset and prevent keys (4th argument) $beforeItems = array_slice($input, 0, $offset, true); $afterItems = array_slice($input, $offset, null, true); if ($length !== null) { $length = (int)$length; // remove items while ($length > 0) { array_shift($afterItems); $length--; } } $input = $beforeItems + $replacement + $afterItems; print_r($input);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [a] => b [c] => d [e] => f [w] => x [y] => z [k] => l )

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:
50.75 ms | 401 KiB | 8 Q