3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_group(array $array, callable|string $callback): array { $groups = []; if (!is_callable($callback)) { return $groups; } foreach ($array as $key => $value) { $groups[call_user_func($callback, $value)][$key] = $value; } return $groups; } $people = [ ["name" => "Billy Jean", "filter" => false], ["name" => "Ronald Reagan", "filter" => true], ["name" => "Bill Clinton", "filter" => true], ["name" => "Michael Jackson", "filter" => false], ["name" => "Johnny Cash", "filter" => false], ]; var_export( array_group( $people, fn($p) => substr($p["name"], 0, 4) ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rQZnu
function name:  (null)
number of ops:  10
compiled vars:  !0 = $people
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, <array>
   22     1        INIT_FCALL                                               'var_export'
   23     2        INIT_FCALL                                               'array_group'
   24     3        SEND_VAR                                                 !0
   25     4        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
   26     5        SEND_VAL                                                 ~2
   23     6        DO_FCALL                                      0  $3      
   26     7        SEND_VAR                                                 $3
   22     8        DO_ICALL                                                 
   27     9      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rQZnu
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'substr'
          2        FETCH_DIM_R                                      ~1      !0, 'name'
          3        SEND_VAL                                                 ~1
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 4
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   26     8*     > RETURN                                                   null

End of Dynamic Function 0

Function array_group:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/rQZnu
function name:  array_group
number of ops:  25
compiled vars:  !0 = $array, !1 = $callback, !2 = $groups, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3        INIT_FCALL                                               'is_callable'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $6      
          6        BOOL_NOT                                         ~7      $6
          7      > JMPZ                                                     ~7, ->10
    6     8    >   VERIFY_RETURN_TYPE                                       !2
          9      > RETURN                                                   !2
    8    10    > > FE_RESET_R                                       $8      !0, ->20
         11    > > FE_FETCH_R                                       ~9      $8, !3, ->20
         12    >   ASSIGN                                                   !4, ~9
    9    13        INIT_USER_CALL                                1          'call_user_func', !1
         14        SEND_USER                                                !3
         15        DO_FCALL                                      0  $11     
         16        FETCH_DIM_W                                      $12     !2, $11
         17        ASSIGN_DIM                                               $12, !4
         18        OP_DATA                                                  !3
    8    19      > JMP                                                      ->11
         20    >   FE_FREE                                                  $8
   11    21        VERIFY_RETURN_TYPE                                       !2
         22      > RETURN                                                   !2
   12    23*       VERIFY_RETURN_TYPE                                       
         24*     > RETURN                                                   null

End of function array_group

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.59 ms | 1007 KiB | 17 Q