3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array_1 = array("1a-dogs","2a-cats","3a-birds","4a-people"); $array_2 = array("4a-walking","2a-cats"); function splitArray ($arrayInput) { $arrayOutput = array(); foreach ($array_1 as $element) { $tempArray = explode('-', $array_1); $arrayOutput[$tempArray[0]] = $tempArray[1]; } return $arrayOutput; } $arraySplit1 = splitArray($array_1); $arraySplit2 = splitArray($array_2); print_r($arraySplit1); print_r($arraySplit2); foreach ($arraySplit1 as $key1 => $value1) { if (array_key_exists($key1, $arraySplit2)) { $arraySplit1[$key1] = $arraySplit2[$key1]; } } print_r($arraySplit1);
Output for 5.1.0 - 7.2.0
Notice: Undefined variable: array_1 in /in/o74V1 on line 8 Warning: Invalid argument supplied for foreach() in /in/o74V1 on line 8 Notice: Undefined variable: array_1 in /in/o74V1 on line 8 Warning: Invalid argument supplied for foreach() in /in/o74V1 on line 8 Array ( ) Array ( ) Array ( )
Output for 4.3.0 - 4.3.10, 4.4.0 - 5.0.5
Warning: Invalid argument supplied for foreach() in /in/o74V1 on line 8 Warning: Invalid argument supplied for foreach() in /in/o74V1 on line 8 Array ( ) Array ( ) Array ( )
Output for 4.3.11
Array ( ) Array ( ) Array ( )