3v4l.org

run code in 500+ PHP versions simultaneously
<?php function numberOfPairs($a,$k){ $a=array_count_values($a); // enable use of the very fast isset() function and avoid iterating duplicates ksort($a); // order so that only the lower values need to be iterated foreach($a as $num=>$occur){ if(($double=$num*2)>=$k){ // we are at or past the middle if($double==$k && $occur>1) $result[]=[$num,$k-$num]; // addends are equal and 2 exist, store before break break; }elseif(isset($a[$k-$num])){ // matching addend found, store & continue $result[]=[$num,$k-$num]; } } var_export($result); } $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/LYhH6
function name:  (null)
number of ops:  7
compiled vars:  !0 = $a, !1 = $k
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                       !0, <array>
   17     1        ASSIGN                                                       !1, 12
   18     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
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 37
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 37
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 28
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 20
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 36
Branch analysis from position: 37
Branch analysis from position: 37
filename:       /in/LYhH6
function name:  numberOfPairs
number of ops:  42
compiled vars:  !0 = $a, !1 = $k, !2 = $occur, !3 = $num, !4 = $double, !5 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    3     2        INIT_FCALL                                                   'array_count_values'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                             $6      
          5        ASSIGN                                                       !0, $6
    4     6        INIT_FCALL                                                   'ksort'
          7        SEND_REF                                                     !0
          8        DO_ICALL                                                     
    5     9      > FE_RESET_R                                           $9      !0, ->37
         10    > > FE_FETCH_R                                           ~10     $9, !2, ->37
         11    >   ASSIGN                                                       !3, ~10
    6    12        MUL                                                  ~12     !3, 2
         13        ASSIGN                                               ~13     !4, ~12
         14        IS_SMALLER_OR_EQUAL                                          !1, ~13
         15      > JMPZ                                                         ~14, ->28
    7    16    >   IS_EQUAL                                             ~15     !4, !1
         17      > JMPZ_EX                                              ~15     ~15, ->20
         18    >   IS_SMALLER                                           ~16     1, !2
         19        BOOL                                                 ~15     ~16
         20    > > JMPZ                                                         ~15, ->26
         21    >   INIT_ARRAY                                           ~18     !3
         22        SUB                                                  ~19     !1, !3
         23        ADD_ARRAY_ELEMENT                                    ~18     ~19
         24        ASSIGN_DIM                                                   !5
         25        OP_DATA                                                      ~18
    8    26    > > JMP                                                          ->37
    6    27*       JMP                                                          ->36
    9    28    >   SUB                                                  ~20     !1, !3
         29        ISSET_ISEMPTY_DIM_OBJ                             0          !0, ~20
         30      > JMPZ                                                         ~21, ->36
   10    31    >   INIT_ARRAY                                           ~23     !3
         32        SUB                                                  ~24     !1, !3
         33        ADD_ARRAY_ELEMENT                                    ~23     ~24
         34        ASSIGN_DIM                                                   !5
         35        OP_DATA                                                      ~23
    5    36    > > JMP                                                          ->10
         37    >   FE_FREE                                                      $9
   13    38        INIT_FCALL                                                   'var_export'
         39        SEND_VAR                                                     !5
         40        DO_ICALL                                                     
   14    41      > RETURN                                                       null

End of function numberofpairs

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
171.97 ms | 2616 KiB | 17 Q