3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * Complete the 'mergeArrays' function below. * * The function is expected to return an INTEGER_ARRAY. * The function accepts following parameters: * 1. INTEGER_ARRAY a * 2. INTEGER_ARRAY b */ function mergeArrays($a, $b) { $mergedArray = array_merge($a, $b); $sortedMergedArray = sorter($mergedArray); // for($i=0; $i<count($sortedMergedArray);$i++){ // echo $sortedMergedArray[$i] . "\n"; // } foreach($sortedMergedArray as $value) { echo $value . "\n"; } } function sorter($array) { for($i=0; $i<count($array);$i++){ for($j=$i+1; $j<count($array);$j++){ if($array[$i] > $array[$j]) { $tmp = $array[$i]; $array[$i] = $array[$j]; $array[$j] = $tmp; } } } return $array; } $fptr = fopen(getenv("OUTPUT_PATH"), "w"); $a_count = intval(trim(fgets(STDIN))); $a = array(); for ($i = 0; $i < $a_count; $i++) { $a_item = intval(trim(fgets(STDIN))); $a[] = $a_item; } $b_count = intval(trim(fgets(STDIN))); $b = array(); for ($i = 0; $i < $b_count; $i++) { $b_item = intval(trim(fgets(STDIN))); $b[] = $b_item; } $result = mergeArrays($a, $b); var_dump($result);

preferences:
69.09 ms | 402 KiB | 5 Q