3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( array('relatedOrderNumber' => 10641, 'relationtype' => 1007), array('relatedOrderNumber' => 82010, 'relationtype' => 1007), array('relatedOrderNumber' => 82020, 'relationtype' => 1007), array('relatedOrderNumber' => 82040, 'relationtype' => 1007), array('relatedOrderNumber' => 82040, 'relationtype' => 1013) ); $new = array_reduce( $array, function($carry, $item) { $type = $item['relationtype']; $orderNumber = $item['relatedOrderNumber']; if (!isset($carry[$type])) { $carry[$type] = [orderNumber]; } else { $carry[$type][] = orderNumber; } }, array() ); var_dump($new);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/np688
function name:  (null)
number of ops:  12
compiled vars:  !0 = $array, !1 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        INIT_FCALL                                               'array_reduce'
   12     2        SEND_VAR                                                 !0
   13     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fnp688%3A13%240'
   22     4        SEND_VAL                                                 ~3
   23     5        SEND_VAL                                                 <array>
          6        DO_ICALL                                         $4      
   11     7        ASSIGN                                                   !1, $4
   26     8        INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fnp688%3A13%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/np688
function name:  {closure}
number of ops:  19
compiled vars:  !0 = $carry, !1 = $item, !2 = $type, !3 = $orderNumber
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        FETCH_DIM_R                                      ~4      !1, 'relationtype'
          3        ASSIGN                                                   !2, ~4
   15     4        FETCH_DIM_R                                      ~6      !1, 'relatedOrderNumber'
          5        ASSIGN                                                   !3, ~6
   17     6        ISSET_ISEMPTY_DIM_OBJ                         0  ~8      !0, !2
          7        BOOL_NOT                                         ~9      ~8
          8      > JMPZ                                                     ~9, ->14
   18     9    >   FETCH_CONSTANT                                   ~11     'orderNumber'
         10        INIT_ARRAY                                       ~12     ~11
         11        ASSIGN_DIM                                               !0, !2
         12        OP_DATA                                                  ~12
         13      > JMP                                                      ->18
   20    14    >   FETCH_CONSTANT                                   ~15     'orderNumber'
         15        FETCH_DIM_W                                      $13     !0, !2
         16        ASSIGN_DIM                                               $13
         17        OP_DATA                                                  ~15
   22    18    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fnp688%3A13%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.72 ms | 1396 KiB | 17 Q