3v4l.org

run code in 300+ PHP versions simultaneously
<?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 (!array_key_exists($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 $merged; } var_dump(mergeArray( array( 'a', 'b', 'c', 'd', 'e', 'f', 'g' ), array( 'a', 'b', 'z', 'q' ) ));
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught ArgumentCountError: array_key_exists() expects exactly 2 arguments, 1 given in /in/ulZSM:13 Stack trace: #0 /in/ulZSM(13): array_key_exists(Array) #1 /in/ulZSM(39): mergeArray(Array, Array) #2 {main} thrown in /in/ulZSM on line 13
Process exited with code 255.

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