3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function mergeArray(array $arr1, array $arr2) { $keysStats = array(); foreach ($arr1 as $index => $key) { $keysStats[$key] = array( 'arr1' => $index, 'arr2' => null ); } foreach ($arr1 as $index => $key) { if (!is_array($keys[$key])) { $keysStats[$key] = array( 'arr1' => null ); } $keysStats[$key]['arr2'] = $index; } $merged = array(); foreach (sort($keysStats) as $key => $score) { if (is_null($keysStats['arr2'])) { $merged[] = null; } else { $merged[] = $arr2[$keysStats['arr2']]; } } return $arrMerged; } print_r(mergeArray( array( 'a', 'b', 'c', 'd', 'e', 'f', 'g' ), array( 'a', 'b', 'z', 'q' ) ));
Output for 5.1.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Warning: Invalid argument supplied for foreach() in /in/Ger3D on line 23 Notice: Undefined variable: arrMerged in /in/Ger3D on line 31
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Notice: Undefined variable: keys in /in/Ger3D on line 13 Warning: Invalid argument supplied for foreach() in /in/Ger3D on line 29 Notice: Undefined variable: arrMerged in /in/Ger3D on line 31
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/Ger3D on line 2
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/Ger3D on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_ARRAY, expecting ')' in /in/Ger3D on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/Ger3D on line 2
Process exited with code 255.