3v4l.org

run code in 300+ PHP versions simultaneously
<?php function numberOfPairs($a, $k) { $cnt = 0; $used=[]; for($i=0; $i<count($a); $i++){ for($j=$i; $j<count($a); $j++){ if($a[$i]+$a[$j] == $k && !in_array($a[$i], $used) && !in_array($a[$i],$used)){ $arrRes[$i][0] = $a[$i]; $arrRes[$i][1] = $a[$j]; $used[] = $a[$i]; $used[] = $a[$j]; $used = array_unique($used); $cnt++; } } } sort($arrRes); //print $cnt; $d = $cnt; for($i=0; $i<count($arrRes); $i++){ for($j=0; $j<count($arrRes); $j++){ $diff = array_diff($arrRes[$i], $arrRes[$j]); if($diff == null) $d += 1; } } print $d; Var_dump($arrRes); } $a = [6,6,3,9,3,5,1]; $k = 12; numberOfPairs($a, $k);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lDe5V
function name:  (null)
number of ops:  7
compiled vars:  !0 = $a, !1 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN                                                   !0, <array>
   34     1        ASSIGN                                                   !1, 12
   35     2        INIT_FCALL                                               'numberofpairs'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Function numberofpairs:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 6
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
2 jumps found. (Code = 44) Position 1 = 82, Position 2 = 62
Branch analysis from position: 82
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
2 jumps found. (Code = 44) Position 1 = 78, Position 2 = 64
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 82, Position 2 = 62
Branch analysis from position: 82
Branch analysis from position: 62
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 74
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 78, Position 2 = 64
Branch analysis from position: 78
Branch analysis from position: 64
Branch analysis from position: 74
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 8
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 6
Branch analysis from position: 56
Branch analysis from position: 6
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 28
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 48
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 8
Branch analysis from position: 52
Branch analysis from position: 8
Branch analysis from position: 48
Branch analysis from position: 28
Branch analysis from position: 20
filename:       /in/lDe5V
function name:  numberOfPairs
number of ops:  87
compiled vars:  !0 = $a, !1 = $k, !2 = $cnt, !3 = $used, !4 = $i, !5 = $j, !6 = $arrRes, !7 = $d, !8 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        ASSIGN                                                   !2, 0
    6     3        ASSIGN                                                   !3, <array>
    7     4        ASSIGN                                                   !4, 0
          5      > JMP                                                      ->53
    8     6    >   ASSIGN                                                   !5, !4
          7      > JMP                                                      ->49
    9     8    >   FETCH_DIM_R                                      ~13     !0, !4
          9        FETCH_DIM_R                                      ~14     !0, !5
         10        ADD                                              ~15     ~13, ~14
         11        IS_EQUAL                                         ~16     !1, ~15
         12      > JMPZ_EX                                          ~16     ~16, ->20
         13    >   INIT_FCALL                                               'in_array'
         14        FETCH_DIM_R                                      ~17     !0, !4
         15        SEND_VAL                                                 ~17
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $18     
         18        BOOL_NOT                                         ~19     $18
         19        BOOL                                             ~16     ~19
         20    > > JMPZ_EX                                          ~16     ~16, ->28
         21    >   INIT_FCALL                                               'in_array'
         22        FETCH_DIM_R                                      ~20     !0, !4
         23        SEND_VAL                                                 ~20
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $21     
         26        BOOL_NOT                                         ~22     $21
         27        BOOL                                             ~16     ~22
         28    > > JMPZ                                                     ~16, ->48
   10    29    >   FETCH_DIM_R                                      ~25     !0, !4
         30        FETCH_DIM_W                                      $23     !6, !4
         31        ASSIGN_DIM                                               $23, 0
         32        OP_DATA                                                  ~25
   11    33        FETCH_DIM_R                                      ~28     !0, !5
         34        FETCH_DIM_W                                      $26     !6, !4
         35        ASSIGN_DIM                                               $26, 1
         36        OP_DATA                                                  ~28
   12    37        FETCH_DIM_R                                      ~30     !0, !4
         38        ASSIGN_DIM                                               !3
         39        OP_DATA                                                  ~30
   13    40        FETCH_DIM_R                                      ~32     !0, !5
         41        ASSIGN_DIM                                               !3
         42        OP_DATA                                                  ~32
   14    43        INIT_FCALL                                               'array_unique'
         44        SEND_VAR                                                 !3
         45        DO_ICALL                                         $33     
         46        ASSIGN                                                   !3, $33
   15    47        PRE_INC                                                  !2
    8    48    >   PRE_INC                                                  !5
         49    >   COUNT                                            ~37     !0
         50        IS_SMALLER                                               !5, ~37
         51      > JMPNZ                                                    ~38, ->8
    7    52    >   PRE_INC                                                  !4
         53    >   COUNT                                            ~40     !0
         54        IS_SMALLER                                               !4, ~40
         55      > JMPNZ                                                    ~41, ->6
   19    56    >   INIT_FCALL                                               'sort'
         57        SEND_REF                                                 !6
         58        DO_ICALL                                                 
   21    59        ASSIGN                                                   !7, !2
   22    60        ASSIGN                                                   !4, 0
         61      > JMP                                                      ->79
   23    62    >   ASSIGN                                                   !5, 0
         63      > JMP                                                      ->75
   24    64    >   INIT_FCALL                                               'array_diff'
         65        FETCH_DIM_R                                      ~46     !6, !4
         66        SEND_VAL                                                 ~46
         67        FETCH_DIM_R                                      ~47     !6, !5
         68        SEND_VAL                                                 ~47
         69        DO_ICALL                                         $48     
         70        ASSIGN                                                   !8, $48
   25    71        IS_EQUAL                                                 !8, null
         72      > JMPZ                                                     ~50, ->74
   26    73    >   ASSIGN_OP                                     1          !7, 1
   23    74    >   PRE_INC                                                  !5
         75    >   COUNT                                            ~53     !6
         76        IS_SMALLER                                               !5, ~53
         77      > JMPNZ                                                    ~54, ->64
   22    78    >   PRE_INC                                                  !4
         79    >   COUNT                                            ~56     !6
         80        IS_SMALLER                                               !4, ~56
         81      > JMPNZ                                                    ~57, ->62
   29    82    >   ECHO                                                     !7
   30    83        INIT_FCALL                                               'var_dump'
         84        SEND_VAR                                                 !6
         85        DO_ICALL                                                 
   31    86      > RETURN                                                   null

End of function numberofpairs

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.15 ms | 1026 KiB | 19 Q