3v4l.org

run code in 500+ 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 = 47
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 6
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 56
Branch analysis from position: 76
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 72, Position 2 = 58
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 56
Branch analysis from position: 76
Branch analysis from position: 56
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 68
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 72, Position 2 = 58
Branch analysis from position: 72
Branch analysis from position: 58
Branch analysis from position: 68
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 8
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 6
Branch analysis from position: 50
Branch analysis from position: 6
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 22
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 42
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 8
Branch analysis from position: 46
Branch analysis from position: 8
Branch analysis from position: 42
Branch analysis from position: 22
Branch analysis from position: 17
filename:       /in/lDe5V
function name:  numberOfPairs
number of ops:  81
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                                                          ->47
    8     6    >   ASSIGN                                                       !5, !4
          7      > JMP                                                          ->43
    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, ->17
         13    >   FETCH_DIM_R                                          ~17     !0, !4
         14        FRAMELESS_ICALL_2                in_array            ~18     ~17, !3
         15        BOOL_NOT                                             ~19     ~18
         16        BOOL                                                 ~16     ~19
         17    > > JMPZ_EX                                              ~16     ~16, ->22
         18    >   FETCH_DIM_R                                          ~20     !0, !4
         19        FRAMELESS_ICALL_2                in_array            ~21     ~20, !3
         20        BOOL_NOT                                             ~22     ~21
         21        BOOL                                                 ~16     ~22
         22    > > JMPZ                                                         ~16, ->42
   10    23    >   FETCH_DIM_R                                          ~25     !0, !4
         24        FETCH_DIM_W                                          $23     !6, !4
         25        ASSIGN_DIM                                                   $23, 0
         26        OP_DATA                                                      ~25
   11    27        FETCH_DIM_R                                          ~28     !0, !5
         28        FETCH_DIM_W                                          $26     !6, !4
         29        ASSIGN_DIM                                                   $26, 1
         30        OP_DATA                                                      ~28
   12    31        FETCH_DIM_R                                          ~30     !0, !4
         32        ASSIGN_DIM                                                   !3
         33        OP_DATA                                                      ~30
   13    34        FETCH_DIM_R                                          ~32     !0, !5
         35        ASSIGN_DIM                                                   !3
         36        OP_DATA                                                      ~32
   14    37        INIT_FCALL                                                   'array_unique'
         38        SEND_VAR                                                     !3
         39        DO_ICALL                                             $33     
         40        ASSIGN                                                       !3, $33
   15    41        PRE_INC                                                      !2
    8    42    >   PRE_INC                                                      !5
         43    >   COUNT                                                ~37     !0
         44        IS_SMALLER                                                   !5, ~37
         45      > JMPNZ                                                        ~38, ->8
    7    46    >   PRE_INC                                                      !4
         47    >   COUNT                                                ~40     !0
         48        IS_SMALLER                                                   !4, ~40
         49      > JMPNZ                                                        ~41, ->6
   19    50    >   INIT_FCALL                                                   'sort'
         51        SEND_REF                                                     !6
         52        DO_ICALL                                                     
   21    53        ASSIGN                                                       !7, !2
   22    54        ASSIGN                                                       !4, 0
         55      > JMP                                                          ->73
   23    56    >   ASSIGN                                                       !5, 0
         57      > JMP                                                          ->69
   24    58    >   INIT_FCALL                                                   'array_diff'
         59        FETCH_DIM_R                                          ~46     !6, !4
         60        SEND_VAL                                                     ~46
         61        FETCH_DIM_R                                          ~47     !6, !5
         62        SEND_VAL                                                     ~47
         63        DO_ICALL                                             $48     
         64        ASSIGN                                                       !8, $48
   25    65        IS_EQUAL                                                     !8, null
         66      > JMPZ                                                         ~50, ->68
   26    67    >   ASSIGN_OP                                         1          !7, 1
   23    68    >   PRE_INC                                                      !5
         69    >   COUNT                                                ~53     !6
         70        IS_SMALLER                                                   !5, ~53
         71      > JMPNZ                                                        ~54, ->58
   22    72    >   PRE_INC                                                      !4
         73    >   COUNT                                                ~56     !6
         74        IS_SMALLER                                                   !4, ~56
         75      > JMPNZ                                                        ~57, ->56
   29    76    >   ECHO                                                         !7
   30    77        INIT_FCALL                                                   'var_dump'
         78        SEND_VAR                                                     !6
         79        DO_ICALL                                                     
   31    80      > RETURN                                                       null

End of function numberofpairs

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
196.67 ms | 2708 KiB | 18 Q