3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = [ "action: Added; amount: 1; code: RNA1; name: Mens Organic T-shirt; colour: White; size: XL", "action: Subtracted; amount: 7; code: RNC1; name: Kids Basic T-shirt; colour: Denim Blue; size: 3-4y", "action: Added; amount: 20; code: RNV1; name: Gift Voucher; style: Mens; value: £20", ]; $keyed = array_reduce($arr, function($collector, $value) { $collector[] = array_reduce(explode('; ', trim($value, '; ')), function($collector, $value) { $parts = explode(': ', $value); $collector[$parts[0]] = $parts[1]; return $collector; }, []); return $collector; }, []); var_dump($keyed);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lLl6T
function name:  (null)
number of ops:  12
compiled vars:  !0 = $arr, !1 = $keyed
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    9     1        INIT_FCALL                                                   'array_reduce'
          2        SEND_VAR                                                     !0
          3        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
   18     4        SEND_VAL                                                     ~3
          5        SEND_VAL                                                     <array>
    9     6        DO_ICALL                                             $4      
          7        ASSIGN                                                       !1, $4
   20     8        INIT_FCALL                                                   'var_dump'
          9        SEND_VAR                                                     !1
         10        DO_ICALL                                                     
         11      > 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/lLl6T
function name:  {closure:/in/lLl6T:9}
number of ops:  17
compiled vars:  !0 = $collector, !1 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   10     2        INIT_FCALL                                                   'array_reduce'
          3        INIT_FCALL                                                   'explode'
          4        SEND_VAL                                                     '%3B+'
          5        FRAMELESS_ICALL_2                trim                ~3      !1, '%3B+'
          6        SEND_VAL                                                     ~3
          7        DO_ICALL                                             $4      
          8        SEND_VAR                                                     $4
          9        DECLARE_LAMBDA_FUNCTION                              ~5      [0]
   15    10        SEND_VAL                                                     ~5
         11        SEND_VAL                                                     <array>
   10    12        DO_ICALL                                             $6      
         13        ASSIGN_DIM                                                   !0
   15    14        OP_DATA                                                      $6
   17    15      > RETURN                                                       !0
   18    16*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lLl6T
function name:  {closure:{closure:/in/lLl6T:9}:10}
number of ops:  13
compiled vars:  !0 = $collector, !1 = $value, !2 = $parts
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   11     2        INIT_FCALL                                                   'explode'
          3        SEND_VAL                                                     '%3A+'
          4        SEND_VAR                                                     !1
          5        DO_ICALL                                             $3      
          6        ASSIGN                                                       !2, $3
   12     7        FETCH_DIM_R                                          ~5      !2, 0
          8        FETCH_DIM_R                                          ~7      !2, 1
          9        ASSIGN_DIM                                                   !0, ~5
         10        OP_DATA                                                      ~7
   14    11      > RETURN                                                       !0
   15    12*     > RETURN                                                       null

End of Dynamic Function 0

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.19 ms | 2302 KiB | 16 Q