3v4l.org

run code in 300+ PHP versions simultaneously
<?php $original = [ '1439045372' => ['price' => 10], '1439131770' => ['price' => 11], '1439218169' => ['price' => 14], '1439304572' => ['price' => 15], '1439390970' => ['price' => 12], ]; $add_to_array = ["3","4","5"]; $n = 1; $result = []; foreach ($original as $key => $item){ $add = $item; if(in_array($n, $add_to_array)){ $add ['data'] = $n; } $result [$key]= $add; $n++; } var_dump($result);
Output for git.master, git.master_jit, rfc.property-hooks
array(5) { [1439045372]=> array(1) { ["price"]=> int(10) } [1439131770]=> array(1) { ["price"]=> int(11) } [1439218169]=> array(2) { ["price"]=> int(14) ["data"]=> int(3) } [1439304572]=> array(2) { ["price"]=> int(15) ["data"]=> int(4) } [1439390970]=> array(2) { ["price"]=> int(12) ["data"]=> int(5) } }

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:
36.15 ms | 402 KiB | 8 Q