3v4l.org

run code in 300+ PHP versions simultaneously
<?php function countUnique($a) { $acv=array_count_values($a); $n=0; foreach ($acv as $f) if ($f==1) $n++; return $n; } function countUniqueTML($a) { return array_reduce( array_count_values($a), function($c, $i) { return ($i === 1) ? $c + 1 : $c; }, 0); } function countUniqueGG($a) { $cardinal=[]; foreach($a as $v) if (isset($cardinal[$v])) $cardinal[$v] = 0; else $cardinal[$v] = 1; return array_sum($cardinal); } $a=[1,1,2,2,2,5,6]; echo countUniqueTML($a); echo "\n"; echo countUnique($a); echo "\n"; echo countUnique($a);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/13k6s
function name:  (null)
number of ops:  16
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ASSIGN                                                   !0, <array>
   29     1        INIT_FCALL                                               'countuniquetml'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
   30     5        ECHO                                                     '%0A'
   31     6        INIT_FCALL                                               'countunique'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $3      
          9        ECHO                                                     $3
   32    10        ECHO                                                     '%0A'
   33    11        INIT_FCALL                                               'countunique'
         12        SEND_VAR                                                 !0
         13        DO_FCALL                                      0  $4      
         14        ECHO                                                     $4
         15      > RETURN                                                   1

Function countunique:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 11
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/13k6s
function name:  countUnique
number of ops:  15
compiled vars:  !0 = $a, !1 = $acv, !2 = $n, !3 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'array_count_values'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
    6     5        ASSIGN                                                   !2, 0
    7     6      > FE_RESET_R                                       $7      !1, ->12
          7    > > FE_FETCH_R                                               $7, !3, ->12
          8    >   IS_EQUAL                                                 !3, 1
          9      > JMPZ                                                     ~8, ->11
         10    >   PRE_INC                                                  !2
         11    > > JMP                                                      ->7
         12    >   FE_FREE                                                  $7
    8    13      > RETURN                                                   !2
    9    14*     > RETURN                                                   null

End of function countunique

Function countuniquetml:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/13k6s
function name:  countUniqueTML
number of ops:  12
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'array_reduce'
   14     2        INIT_FCALL                                               'array_count_values'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
   15     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F13k6s%3A15%240'
          7        SEND_VAL                                                 ~2
   16     8        SEND_VAL                                                 0
          9        DO_ICALL                                         $3      
         10      > RETURN                                                   $3
   17    11*     > RETURN                                                   null

End of function countuniquetml

Function %00%7Bclosure%7D%2Fin%2F13k6s%3A15%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/13k6s
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $c, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        IS_IDENTICAL                                             !1, 1
          3      > JMPZ                                                     ~2, ->7
          4    >   ADD                                              ~3      !0, 1
          5        QM_ASSIGN                                        ~4      ~3
          6      > JMP                                                      ->8
          7    >   QM_ASSIGN                                        ~4      !0
          8    > > RETURN                                                   ~4
          9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F13k6s%3A15%240

Function countuniquegg:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/13k6s
function name:  countUniqueGG
number of ops:  18
compiled vars:  !0 = $a, !1 = $cardinal, !2 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        ASSIGN                                                   !1, <array>
   22     2      > FE_RESET_R                                       $4      !0, ->12
          3    > > FE_FETCH_R                                               $4, !2, ->12
   23     4    >   ISSET_ISEMPTY_DIM_OBJ                         0          !1, !2
          5      > JMPZ                                                     ~5, ->9
          6    >   ASSIGN_DIM                                               !1, !2
          7        OP_DATA                                                  0
          8      > JMP                                                      ->11
          9    >   ASSIGN_DIM                                               !1, !2
         10        OP_DATA                                                  1
   22    11    > > JMP                                                      ->3
         12    >   FE_FREE                                                  $4
   24    13        INIT_FCALL                                               'array_sum'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $8      
         16      > RETURN                                                   $8
   25    17*     > RETURN                                                   null

End of function countuniquegg

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.16 ms | 1407 KiB | 22 Q