3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array_1=array("1a-dogs","2a-cats","3a-birds","4a-people"); $array_2=array("4a-walking","2a-cats"); function getKeyStartingWith($array, $startVal){ foreach($array as $key => $val){ if(strpos($val, $startVal) === 0){ return $key; } } return false; } function getMergedArray($array_1, $array_2){ $array_3 = array(); foreach($array_1 as $key => $val){ $startVal = substr($val, 0, 2); $array_2_key = getKeyStartingWith($array_2, $startVal); if($array_2_key !== false){ $array_3[$key] = $array_2[$array_2_key]; } else { $array_3[$key] = $val; } } return $array_3; } $array_1 = getMergedArray($array_1, $array_2); print_r($array_1);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => 1a-dogs [1] => 2a-cats [2] => 3a-birds [3] => 4a-walking )

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