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);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 20
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 46
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 46
Branch analysis from position: 60
Branch analysis from position: 46
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 20
Branch analysis from position: 34
Branch analysis from position: 20
filename:       /in/eRMRL
function name:  (null)
number of ops:  69
compiled vars:  !0 = $fptr, !1 = $a_count, !2 = $a, !3 = $i, !4 = $a_item, !5 = $b_count, !6 = $b, !7 = $b_item, !8 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   INIT_FCALL                                               'fopen'
          1        INIT_FCALL                                               'getenv'
          2        SEND_VAL                                                 'OUTPUT_PATH'
          3        DO_ICALL                                         $9      
          4        SEND_VAR                                                 $9
          5        SEND_VAL                                                 'w'
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !0, $10
   45     8        INIT_FCALL                                               'trim'
          9        INIT_FCALL                                               'fgets'
         10        FETCH_CONSTANT                                   ~12     'STDIN'
         11        SEND_VAL                                                 ~12
         12        DO_ICALL                                         $13     
         13        SEND_VAR                                                 $13
         14        DO_ICALL                                         $14     
         15        CAST                                          4  ~15     $14
         16        ASSIGN                                                   !1, ~15
   47    17        ASSIGN                                                   !2, <array>
   49    18        ASSIGN                                                   !3, 0
         19      > JMP                                                      ->32
   50    20    >   INIT_FCALL                                               'trim'
         21        INIT_FCALL                                               'fgets'
         22        FETCH_CONSTANT                                   ~19     'STDIN'
         23        SEND_VAL                                                 ~19
         24        DO_ICALL                                         $20     
         25        SEND_VAR                                                 $20
         26        DO_ICALL                                         $21     
         27        CAST                                          4  ~22     $21
         28        ASSIGN                                                   !4, ~22
   51    29        ASSIGN_DIM                                               !2
         30        OP_DATA                                                  !4
   49    31        PRE_INC                                                  !3
         32    >   IS_SMALLER                                               !3, !1
         33      > JMPNZ                                                    ~26, ->20
   54    34    >   INIT_FCALL                                               'trim'
         35        INIT_FCALL                                               'fgets'
         36        FETCH_CONSTANT                                   ~27     'STDIN'
         37        SEND_VAL                                                 ~27
         38        DO_ICALL                                         $28     
         39        SEND_VAR                                                 $28
         40        DO_ICALL                                         $29     
         41        CAST                                          4  ~30     $29
         42        ASSIGN                                                   !5, ~30
   56    43        ASSIGN                                                   !6, <array>
   58    44        ASSIGN                                                   !3, 0
         45      > JMP                                                      ->58
   59    46    >   INIT_FCALL                                               'trim'
         47        INIT_FCALL                                               'fgets'
         48        FETCH_CONSTANT                                   ~34     'STDIN'
         49        SEND_VAL                                                 ~34
         50        DO_ICALL                                         $35     
         51        SEND_VAR                                                 $35
         52        DO_ICALL                                         $36     
         53        CAST                                          4  ~37     $36
         54        ASSIGN                                                   !7, ~37
   60    55        ASSIGN_DIM                                               !6
         56        OP_DATA                                                  !7
   58    57        PRE_INC                                                  !3
         58    >   IS_SMALLER                                               !3, !5
         59      > JMPNZ                                                    ~41, ->46
   63    60    >   INIT_FCALL                                               'mergearrays'
         61        SEND_VAR                                                 !2
         62        SEND_VAR                                                 !6
         63        DO_FCALL                                      0  $42     
         64        ASSIGN                                                   !8, $42
   65    65        INIT_FCALL                                               'var_dump'
         66        SEND_VAR                                                 !8
         67        DO_ICALL                                                 
         68      > RETURN                                                   1

Function mergearrays:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/eRMRL
function name:  mergeArrays
number of ops:  18
compiled vars:  !0 = $a, !1 = $b, !2 = $mergedArray, !3 = $sortedMergedArray, !4 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        INIT_FCALL                                               'array_merge'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !2, $5
   18     7        INIT_FCALL_BY_NAME                                       'sorter'
          8        SEND_VAR_EX                                              !2
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !3, $7
   23    11      > FE_RESET_R                                       $9      !3, ->16
         12    > > FE_FETCH_R                                               $9, !4, ->16
   24    13    >   CONCAT                                           ~10     !4, '%0A'
         14        ECHO                                                     ~10
   23    15      > JMP                                                      ->12
         16    >   FE_FREE                                                  $9
   26    17      > RETURN                                                   null

End of function mergearrays

Function sorter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 3
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 6
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 3
Branch analysis from position: 25
Branch analysis from position: 3
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 6
Branch analysis from position: 21
Branch analysis from position: 6
Branch analysis from position: 17
filename:       /in/eRMRL
function name:  sorter
number of ops:  27
compiled vars:  !0 = $array, !1 = $i, !2 = $j, !3 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   30     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->22
   31     3    >   ADD                                              ~5      !1, 1
          4        ASSIGN                                                   !2, ~5
          5      > JMP                                                      ->18
   32     6    >   FETCH_DIM_R                                      ~7      !0, !1
          7        FETCH_DIM_R                                      ~8      !0, !2
          8        IS_SMALLER                                               ~8, ~7
          9      > JMPZ                                                     ~9, ->17
   33    10    >   FETCH_DIM_R                                      ~10     !0, !1
         11        ASSIGN                                                   !3, ~10
   34    12        FETCH_DIM_R                                      ~13     !0, !2
         13        ASSIGN_DIM                                               !0, !1
         14        OP_DATA                                                  ~13
   35    15        ASSIGN_DIM                                               !0, !2
         16        OP_DATA                                                  !3
   31    17    >   PRE_INC                                                  !2
         18    >   COUNT                                            ~16     !0
         19        IS_SMALLER                                               !2, ~16
         20      > JMPNZ                                                    ~17, ->6
   30    21    >   PRE_INC                                                  !1
         22    >   COUNT                                            ~19     !0
         23        IS_SMALLER                                               !1, ~19
         24      > JMPNZ                                                    ~20, ->3
   40    25    > > RETURN                                                   !0
   41    26*     > RETURN                                                   null

End of function sorter

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
193.64 ms | 1411 KiB | 26 Q