3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ ['id' => 111, 'text' => 'yellow'], ['id' => 111, 'text' => 'red'], ['id' => 112, 'text' => 'green'], ]; $result = array_map(function($item) {return [ 'id' => $item['id'], 'text' => implode(', ', $item['colors']), ];}, array_reduce($data, function($reduced, $item){ if (!isset($reduced[$item['id']])) $reduced[$item['id']] = $item; $reduced[$item['id']]['colors'][] = $item['text']; return $reduced; }, [])); var_dump($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QCRV6
function name:  (null)
number of ops:  17
compiled vars:  !0 = $data, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        INIT_FCALL                                               'array_map'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQCRV6%3A9%240'
   12     3        SEND_VAL                                                 ~3
          4        INIT_FCALL                                               'array_reduce'
          5        SEND_VAR                                                 !0
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQCRV6%3A12%241'
   16     7        SEND_VAL                                                 ~4
          8        SEND_VAL                                                 <array>
          9        DO_ICALL                                         $5      
         10        SEND_VAR                                                 $5
         11        DO_ICALL                                         $6      
    9    12        ASSIGN                                                   !1, $6
   18    13        INIT_FCALL                                               'var_dump'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FQCRV6%3A9%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QCRV6
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        FETCH_DIM_R                                      ~1      !0, 'id'
          2        INIT_ARRAY                                       ~2      ~1, 'id'
   11     3        INIT_FCALL                                               'implode'
          4        SEND_VAL                                                 '%2C+'
          5        FETCH_DIM_R                                      ~3      !0, 'colors'
          6        SEND_VAL                                                 ~3
          7        DO_ICALL                                         $4      
          8        ADD_ARRAY_ELEMENT                                ~2      $4, 'text'
          9      > RETURN                                                   ~2
   12    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQCRV6%3A9%240

Function %00%7Bclosure%7D%2Fin%2FQCRV6%3A12%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/QCRV6
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $reduced, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
          0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        FETCH_DIM_R                                      ~2      !1, 'id'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      !0, ~2
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->9
          6    >   FETCH_DIM_R                                      ~5      !1, 'id'
          7        ASSIGN_DIM                                               !0, ~5
          8        OP_DATA                                                  !1
   14     9    >   FETCH_DIM_R                                      ~7      !1, 'id'
         10        FETCH_DIM_R                                      ~11     !1, 'text'
         11        FETCH_DIM_W                                      $8      !0, ~7
         12        FETCH_DIM_W                                      $9      $8, 'colors'
         13        ASSIGN_DIM                                               $9
         14        OP_DATA                                                  ~11
   15    15      > RETURN                                                   !0
   16    16*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQCRV6%3A12%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.26 ms | 1400 KiB | 21 Q