3v4l.org

run code in 300+ 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}
number of ops:  20
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        INIT_FCALL                                               'trim'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 '%3B+'
          8        DO_ICALL                                         $3      
          9        SEND_VAR                                                 $3
         10        DO_ICALL                                         $4      
         11        SEND_VAR                                                 $4
         12        DECLARE_LAMBDA_FUNCTION                          ~5      [0]
   15    13        SEND_VAL                                                 ~5
         14        SEND_VAL                                                 <array>
   10    15        DO_ICALL                                         $6      
         16        ASSIGN_DIM                                               !0
   15    17        OP_DATA                                                  $6
   17    18      > RETURN                                                   !0
   18    19*     > 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}
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.0.0


preferences:
139.73 ms | 1461 KiB | 17 Q