3v4l.org

run code in 300+ PHP versions simultaneously
<?php function position_merge(array $arr1,array $arr2) { $result=array_merge($arr1,$arr2); array_walk($result,function(&$item,$idx){ $item["array_index"]=$idx;// Make sure this key is not used }); usort($result,function($a,$b){ return $a["position"]-$b["position"]?:$a["array_index"]-$b["array_index"]; }); array_walk($result,function(&$item){ unset($item["array_index"]); }); return $result; } $array1 = array( array('name' => 'Bob', 'position' => 1), array('name' => 'Tim', 'position' => 1), array('name' => 'Alf', 'position' => 3), array('name' => 'Jon', 'position' => 3) ); $array2 = array( array('name' => 'Tom', 'position' => 2), array('name' => 'Joe', 'position' => 2), array('name' => 'Jim', 'position' => 2), array('name' => 'Kev', 'position' => 2) ); print_r(position_merge($array1,$array2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BgDK0
function name:  (null)
number of ops:  10
compiled vars:  !0 = $array1, !1 = $array2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, <array>
   23     1        ASSIGN                                                   !1, <array>
   29     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'position_merge'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function position_merge:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BgDK0
function name:  position_merge
number of ops:  24
compiled vars:  !0 = $arr1, !1 = $arr2, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'array_merge'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !2, $3
    5     7        INIT_FCALL                                               'array_walk'
          8        SEND_REF                                                 !2
          9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBgDK0%3A5%240'
    7    10        SEND_VAL                                                 ~5
         11        DO_ICALL                                                 
    8    12        INIT_FCALL                                               'usort'
         13        SEND_REF                                                 !2
         14        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBgDK0%3A8%241'
   10    15        SEND_VAL                                                 ~7
         16        DO_ICALL                                                 
   11    17        INIT_FCALL                                               'array_walk'
         18        SEND_REF                                                 !2
         19        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBgDK0%3A11%242'
   13    20        SEND_VAL                                                 ~9
         21        DO_ICALL                                                 
   14    22      > RETURN                                                   !2
   15    23*     > RETURN                                                   null

End of function position_merge

Function %00%7Bclosure%7D%2Fin%2FBgDK0%3A5%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BgDK0
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $item, !1 = $idx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        ASSIGN_DIM                                               !0, 'array_index'
          3        OP_DATA                                                  !1
    7     4      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBgDK0%3A5%240

Function %00%7Bclosure%7D%2Fin%2FBgDK0%3A8%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BgDK0
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        FETCH_DIM_R                                      ~2      !0, 'position'
          3        FETCH_DIM_R                                      ~3      !1, 'position'
          4        SUB                                              ~4      ~2, ~3
          5        JMP_SET                                          ~5      ~4, ->10
          6        FETCH_DIM_R                                      ~6      !0, 'array_index'
          7        FETCH_DIM_R                                      ~7      !1, 'array_index'
          8        SUB                                              ~8      ~6, ~7
          9        QM_ASSIGN                                        ~5      ~8
         10      > RETURN                                                   ~5
   10    11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBgDK0%3A8%241

Function %00%7Bclosure%7D%2Fin%2FBgDK0%3A11%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BgDK0
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        UNSET_DIM                                                !0, 'array_index'
   13     2      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBgDK0%3A11%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.6 ms | 1403 KiB | 22 Q