3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mergeArray(array $arr1, array $arr2) { $keysStats = array(); foreach ($arr1 as $index => $key) { $keys[$key] = array( 'arr1' => $index, 'arr2' => null ); } foreach ($arr1 as $index => $key) { if (!is_array($keys[$key])) { $keys[$key] = array( 'arr1' => null ); } $keys[$key]['arr2'] = $index; } $merged = array(); foreach (sort($keys) as $key => $score) { if (is_null($keys['arr2'])) { $merged[] = null; } else { $merged[] = $arr2[$keys['arr2']]; } } return $arrMerged; } print_r(mergeArray( array( 'a', 'b', 'c', 'd', 'e', 'f', 'g' ), array( 'a', 'b', 'z', 'q' ) ));
Output for git.master, git.master_jit
Warning: foreach() argument must be of type array|object, bool given in /in/7J5Jn on line 23 Warning: Undefined variable $arrMerged in /in/7J5Jn on line 31
Output for rfc.property-hooks
Warning: foreach() argument must be of type array|object, true given in /in/7J5Jn on line 23 Warning: Undefined variable $arrMerged in /in/7J5Jn on line 31

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