3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array_1=array("1a-dogs","2a-cats","3a-birds","4a-people"); $array_2=array("4a-walking","2a-cats"); function getKeyStartingWith($array, $startVal){ foreach($array as $key => $val){ if(strpos($val, $startVal) === 0){ return $key; } } return false; } function getMergedArray($array_1, $array_2){ $array_3 = array(); foreach($array_1 as $key => $val){ $startVal = substr($val, 0, 2); $array_2_key = getKeyStartingWith($array_2, $startVal); if($array_2_key !== false){ $array_3[$key] = $array_2[$array_2_key]; } else { $array_3[$key] = $val; } } return $array_3; } $array_1 = getMergedArray($array_1, $array_2); print_r($array_1);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kUC3r
function name:  (null)
number of ops:  11
compiled vars:  !0 = $array_1, !1 = $array_2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1        ASSIGN                                                   !1, <array>
   28     2        INIT_FCALL                                               'getmergedarray'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !0, $4
   30     7        INIT_FCALL                                               'print_r'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function getkeystartingwith:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/kUC3r
function name:  getKeyStartingWith
number of ops:  17
compiled vars:  !0 = $array, !1 = $startVal, !2 = $val, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2      > FE_RESET_R                                       $4      !0, ->14
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->14
          4    >   ASSIGN                                                   !3, ~5
    7     5        INIT_FCALL                                               'strpos'
          6        SEND_VAR                                                 !2
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $7      
          9        IS_IDENTICAL                                             $7, 0
         10      > JMPZ                                                     ~8, ->13
    8    11    >   FE_FREE                                                  $4
         12      > RETURN                                                   !3
    6    13    > > JMP                                                      ->3
         14    >   FE_FREE                                                  $4
   11    15      > RETURN                                                   <false>
   12    16*     > RETURN                                                   null

End of function getkeystartingwith

Function getmergedarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 26
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 26
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/kUC3r
function name:  getMergedArray
number of ops:  29
compiled vars:  !0 = $array_1, !1 = $array_2, !2 = $array_3, !3 = $val, !4 = $key, !5 = $startVal, !6 = $array_2_key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        ASSIGN                                                   !2, <array>
   16     3      > FE_RESET_R                                       $8      !0, ->26
          4    > > FE_FETCH_R                                       ~9      $8, !3, ->26
          5    >   ASSIGN                                                   !4, ~9
   17     6        INIT_FCALL                                               'substr'
          7        SEND_VAR                                                 !3
          8        SEND_VAL                                                 0
          9        SEND_VAL                                                 2
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !5, $11
   18    12        INIT_FCALL                                               'getkeystartingwith'
         13        SEND_VAR                                                 !1
         14        SEND_VAR                                                 !5
         15        DO_FCALL                                      0  $13     
         16        ASSIGN                                                   !6, $13
   19    17        TYPE_CHECK                                  1018          !6
         18      > JMPZ                                                     ~15, ->23
   20    19    >   FETCH_DIM_R                                      ~17     !1, !6
         20        ASSIGN_DIM                                               !2, !4
         21        OP_DATA                                                  ~17
         22      > JMP                                                      ->25
   22    23    >   ASSIGN_DIM                                               !2, !4
         24        OP_DATA                                                  !3
   16    25    > > JMP                                                      ->4
         26    >   FE_FREE                                                  $8
   25    27      > RETURN                                                   !2
   26    28*     > RETURN                                                   null

End of function getmergedarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.5 ms | 1394 KiB | 21 Q