3v4l.org

run code in 500+ PHP versions simultaneously
<?php function array_udiff_userland(callable $cb, array $left, array $right) { usort($left, $cb); usort($right, $cb); reset($right); $result = []; $cur = each($right); foreach ($left as $el) { if ($cur === false) { // if we are already at the end of $right list //(it could be because $right was empty or if we reached its end in the iterations) $result[] = $el; continue; } $dif = $cb($el, $cur[1]); if ($dif > 0) { // $el > $cur - we need to advance $cur further until we find equal or greater element while ($dif > 0 && ($cur = each($right)) !== false) { $dif = $cb($el, $cur[1]); } if ($cur === false) { // $right list has reached its end $result[] = $el; continue; } } if ($dif === 0) { // elements are the same - we skip the current element continue; } if ($dif < 0) { $result[] = $el; } } return $result; } $l = [15, 5, 10, 90, 105]; $r = [6, 9, 15, 15, 100, 90, 400]; $cb = function ($l, $r) { return $l - $r; }; var_dump(array_udiff_userland($cb, $l, $r));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P5JdW
function name:  (null)
number of ops:  13
compiled vars:  !0 = $l, !1 = $r, !2 = $cb
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   42     0  E >   ASSIGN                                                       !0, <array>
   43     1        ASSIGN                                                       !1, <array>
   44     2        DECLARE_LAMBDA_FUNCTION                              ~5      [0]
          3        ASSIGN                                                       !2, ~5
   46     4        INIT_FCALL                                                   'var_dump'
          5        INIT_FCALL                                                   'array_udiff_userland'
          6        SEND_VAR                                                     !2
          7        SEND_VAR                                                     !0
          8        SEND_VAR                                                     !1
          9        DO_FCALL                                          0  $7      
         10        SEND_VAR                                                     $7
         11        DO_ICALL                                                     
         12      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P5JdW
function name:  {closure:/in/P5JdW:44}
number of ops:  5
compiled vars:  !0 = $l, !1 = $r
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   44     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        SUB                                                  ~2      !0, !1
          3      > RETURN                                                       ~2
          4*     > RETURN                                                       null

End of Dynamic Function 0

Function array_udiff_userland:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 65
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 65
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 26
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 57
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 46) Position 1 = 45, Position 2 = 51
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 36
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 57
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 60
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 64
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 64
Branch analysis from position: 36
2 jumps found. (Code = 46) Position 1 = 45, Position 2 = 51
Branch analysis from position: 45
Branch analysis from position: 51
Branch analysis from position: 51
Branch analysis from position: 57
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
filename:       /in/P5JdW
function name:  array_udiff_userland
number of ops:  68
compiled vars:  !0 = $cb, !1 = $left, !2 = $right, !3 = $result, !4 = $cur, !5 = $el, !6 = $dif
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
    5     3        INIT_FCALL                                                   'usort'
          4        SEND_REF                                                     !1
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                                     
    6     7        INIT_FCALL                                                   'usort'
          8        SEND_REF                                                     !2
          9        SEND_VAR                                                     !0
         10        DO_ICALL                                                     
    7    11        INIT_FCALL                                                   'reset'
         12        SEND_REF                                                     !2
         13        DO_ICALL                                                     
    9    14        ASSIGN                                                       !3, <array>
   10    15        INIT_FCALL_BY_NAME                                           'each'
         16        SEND_VAR_EX                                                  !2
         17        DO_FCALL                                          0  $11     
         18        ASSIGN                                                       !4, $11
   11    19      > FE_RESET_R                                           $13     !1, ->65
         20    > > FE_FETCH_R                                                   $13, !5, ->65
   12    21    >   TYPE_CHECK                                        4          !4
         22      > JMPZ                                                         ~14, ->26
   14    23    >   ASSIGN_DIM                                                   !3
         24        OP_DATA                                                      !5
   15    25      > JMP                                                          ->20
   18    26    >   INIT_DYNAMIC_CALL                                            !0
         27        SEND_VAR_EX                                                  !5
         28        CHECK_FUNC_ARG                                               
         29        FETCH_DIM_FUNC_ARG                                   $16     !4, 1
         30        SEND_FUNC_ARG                                                $16
         31        DO_FCALL                                          0  $17     
         32        ASSIGN                                                       !6, $17
   20    33        IS_SMALLER                                                   0, !6
         34      > JMPZ                                                         ~19, ->57
   21    35    > > JMP                                                          ->43
   22    36    >   INIT_DYNAMIC_CALL                                            !0
         37        SEND_VAR_EX                                                  !5
         38        CHECK_FUNC_ARG                                               
         39        FETCH_DIM_FUNC_ARG                                   $20     !4, 1
         40        SEND_FUNC_ARG                                                $20
         41        DO_FCALL                                          0  $21     
         42        ASSIGN                                                       !6, $21
   21    43    >   IS_SMALLER                                           ~23     0, !6
         44      > JMPZ_EX                                              ~23     ~23, ->51
         45    >   INIT_FCALL_BY_NAME                                           'each'
         46        SEND_VAR_EX                                                  !2
         47        DO_FCALL                                          0  $24     
         48        ASSIGN                                               ~25     !4, $24
         49        TYPE_CHECK                                      1018  ~26     ~25
         50        BOOL                                                 ~23     ~26
         51    > > JMPNZ                                                        ~23, ->36
   24    52    >   TYPE_CHECK                                        4          !4
         53      > JMPZ                                                         ~27, ->57
   25    54    >   ASSIGN_DIM                                                   !3
         55        OP_DATA                                                      !5
   26    56      > JMP                                                          ->20
   30    57    >   IS_IDENTICAL                                                 !6, 0
         58      > JMPZ                                                         ~29, ->60
   31    59    > > JMP                                                          ->20
   34    60    >   IS_SMALLER                                                   !6, 0
         61      > JMPZ                                                         ~30, ->64
   35    62    >   ASSIGN_DIM                                                   !3
         63        OP_DATA                                                      !5
   11    64    > > JMP                                                          ->20
         65    >   FE_FREE                                                      $13
   39    66      > RETURN                                                       !3
   40    67*     > RETURN                                                       null

End of function array_udiff_userland

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
125.69 ms | 491 KiB | 11 Q