3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_partition($array, $callback, $recursive = true) { $ret = array (); $walk = ($recursive) ? 'array_walk_recursive' : 'array_walk'; $walk ( $array, function ($value, $key) use($callback, &$ret) { $index = call_user_func_array ( $callback, array ( $value, $key ) ); if (isset ( $ret [$index] )) $ret [$index] [] = $value; else $ret [$index] = array ( $value ); } ); return $ret; } $p1 = (object) array('a'=>1,'b'=>2); $p2 = (object) array('a'=>1,'b'=>3); $p3 = (object) array('a'=>2,'b'=>4); $posts[] = $p1; $posts[] = $p2; $posts[] = $p3; $posts = array_partition($posts, function ($post, $i) { return $post->a; }, false); print_r($posts); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9tsVd
function name:  (null)
number of ops:  23
compiled vars:  !0 = $p1, !1 = $p2, !2 = $p3, !3 = $posts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   CAST                                          8  ~4      <array>
          1        ASSIGN                                                   !0, ~4
   23     2        CAST                                          8  ~6      <array>
          3        ASSIGN                                                   !1, ~6
   24     4        CAST                                          8  ~8      <array>
          5        ASSIGN                                                   !2, ~8
   25     6        ASSIGN_DIM                                               !3
          7        OP_DATA                                                  !0
   26     8        ASSIGN_DIM                                               !3
          9        OP_DATA                                                  !1
   27    10        ASSIGN_DIM                                               !3
         11        OP_DATA                                                  !2
   29    12        INIT_FCALL                                               'array_partition'
         13        SEND_VAR                                                 !3
         14        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F9tsVd%3A29%241'
   31    15        SEND_VAL                                                 ~13
         16        SEND_VAL                                                 <false>
         17        DO_FCALL                                      0  $14     
   29    18        ASSIGN                                                   !3, $14
   32    19        INIT_FCALL                                               'print_r'
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                                 
   33    22      > RETURN                                                   1

Function array_partition:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
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/9tsVd
function name:  array_partition
number of ops:  18
compiled vars:  !0 = $array, !1 = $callback, !2 = $recursive, !3 = $ret, !4 = $walk
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <true>
    3     3        ASSIGN                                                   !3, <array>
    4     4      > JMPZ                                                     !2, ->7
          5    >   QM_ASSIGN                                        ~6      'array_walk_recursive'
          6      > JMP                                                      ->8
          7    >   QM_ASSIGN                                        ~6      'array_walk'
          8    >   ASSIGN                                                   !4, ~6
    6     9        INIT_DYNAMIC_CALL                                        !4
         10        SEND_VAR_EX                                              !0
         11        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F9tsVd%3A6%240'
         12        BIND_LEXICAL                                             ~8, !1
         13        BIND_LEXICAL                                             ~8, !3
   17    14        SEND_VAL_EX                                              ~8
         15        DO_FCALL                                      0          
   19    16      > RETURN                                                   !3
   20    17*     > RETURN                                                   null

End of function array_partition

Function %00%7Bclosure%7D%2Fin%2F9tsVd%3A6%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9tsVd
function name:  {closure}
number of ops:  21
compiled vars:  !0 = $value, !1 = $key, !2 = $callback, !3 = $ret, !4 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
    7     4        INIT_USER_CALL                                0          'call_user_func_array', !2
    8     5        INIT_ARRAY                                       ~5      !0
    9     6        ADD_ARRAY_ELEMENT                                ~5      !1
          7        SEND_ARRAY                                               ~5
          8        CHECK_UNDEF_ARGS                                         
          9        DO_FCALL                                      0  $6      
    7    10        ASSIGN                                                   !4, $6
   11    11        ISSET_ISEMPTY_DIM_OBJ                         0          !3, !4
         12      > JMPZ                                                     ~8, ->17
   12    13    >   FETCH_DIM_W                                      $9      !3, !4
         14        ASSIGN_DIM                                               $9
         15        OP_DATA                                                  !0
         16      > JMP                                                      ->20
   15    17    >   INIT_ARRAY                                       ~12     !0
   14    18        ASSIGN_DIM                                               !3, !4
   15    19        OP_DATA                                                  ~12
   17    20    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F9tsVd%3A6%240

Function %00%7Bclosure%7D%2Fin%2F9tsVd%3A29%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9tsVd
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $post, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   30     2        FETCH_OBJ_R                                      ~2      !0, 'a'
          3      > RETURN                                                   ~2
   31     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F9tsVd%3A29%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.63 ms | 1403 KiB | 16 Q