3v4l.org

run code in 300+ PHP versions simultaneously
<?php function HacklandElection($arr = []) { $collection = []; foreach ($arr as $voter) { if (array_key_exists($voter, $collection)) { $collection[$voter] += 1; } else { $collection[$voter] = 1; } } $max = max($collection); $collection = array_keys($collection, $max); arsort($collection); return array_shift($collection); } //$mag1 = ['Alex' => 10, 'Harry' => 0, 'Michael' => 2, 'Mary' => -1]; $votes = ["Alex", "Michael", "Harry", "Dave", "Michael", "Victor", "Harry", "Alex", "Mary", "Mary"]; echo HacklandElection($votes);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HIUPi
function name:  (null)
number of ops:  6
compiled vars:  !0 = $votes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, <array>
   25     1        INIT_FCALL                                               'hacklandelection'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function hacklandelection:
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/HIUPi
function name:  HacklandElection
number of ops:  30
compiled vars:  !0 = $arr, !1 = $collection, !2 = $voter, !3 = $max
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV_INIT                                        !0      <array>
    4     1        ASSIGN                                                   !1, <array>
    5     2      > FE_RESET_R                                       $5      !0, ->12
          3    > > FE_FETCH_R                                               $5, !2, ->12
    6     4    >   ARRAY_KEY_EXISTS                                         !2, !1
          5      > JMPZ                                                     ~6, ->9
    7     6    >   ASSIGN_DIM_OP                +=               1          !1, !2
          7        OP_DATA                                                  1
          8      > JMP                                                      ->11
    9     9    >   ASSIGN_DIM                                               !1, !2
         10        OP_DATA                                                  1
    5    11    > > JMP                                                      ->3
         12    >   FE_FREE                                                  $5
   13    13        INIT_FCALL                                               'max'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $9      
         16        ASSIGN                                                   !3, $9
   14    17        INIT_FCALL                                               'array_keys'
         18        SEND_VAR                                                 !1
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $11     
         21        ASSIGN                                                   !1, $11
   15    22        INIT_FCALL                                               'arsort'
         23        SEND_REF                                                 !1
         24        DO_ICALL                                                 
   17    25        INIT_FCALL                                               'array_shift'
         26        SEND_REF                                                 !1
         27        DO_ICALL                                         $14     
         28      > RETURN                                                   $14
   18    29*     > RETURN                                                   null

End of function hacklandelection

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
203.67 ms | 1403 KiB | 22 Q