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 ($arr2 as $index => $key) { if (!is_array($keysStats[$key])) { $keysStats[$key] = array( 'arr1' => null, 'arr2' => $index ); } else { $keysStats[$key]['arr2'] = $index; } } $allKeys = array_keys($keysStats); sort($allKeys); $merged = array(); foreach ($allKeys as $key) { if (is_null($keysStats[$key]['arr2'])) { $merged[] = null; } else { $merged[] = $arr2[$keysStats[$key]['arr2']]; } } return $arrMerged; } print_r(mergeArray( array( 'a', 'b', 'c', 'd', 'e', 'f', 'g' ), array( 'a', 'b', 'z', 'q' ) ));
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Notice: Undefined index: z in /in/WuDnX on line 13 Notice: Undefined index: q in /in/WuDnX on line 13 Notice: Undefined variable: arrMerged in /in/WuDnX on line 36
Output for 5.1.0 - 5.2.17
Notice: Undefined index: z in /in/WuDnX on line 13 Notice: Undefined index: q in /in/WuDnX on line 13 Notice: Undefined variable: arrMerged in /in/WuDnX on line 36
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/WuDnX 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/WuDnX 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/WuDnX on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/WuDnX on line 2
Process exited with code 255.