3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "11111*1; 22222*1; 33333*1; 44444*1"; $array = explode('; ', $string); $new = []; foreach($array as $k => $v){ $parts = explode('*', $v); $new[] = [ 'sku' => $parts[0], 'qty' => $parts[1], ]; } echo json_encode($new, JSON_PRETTY_PRINT); // JSON_PRETTY_PRINT is just for displaying it nicely here
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 22
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 22
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/DnPJk
function name:  (null)
number of ops:  29
compiled vars:  !0 = $string, !1 = $array, !2 = $new, !3 = $v, !4 = $k, !5 = $parts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '11111%2A1%3B+22222%2A1%3B+33333%2A1%3B+44444%2A1'
    3     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%3B+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !1, $7
    4     6        ASSIGN                                                   !2, <array>
    6     7      > FE_RESET_R                                       $10     !1, ->22
          8    > > FE_FETCH_R                                       ~11     $10, !3, ->22
          9    >   ASSIGN                                                   !4, ~11
    7    10        INIT_FCALL                                               'explode'
         11        SEND_VAL                                                 '%2A'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !5, $13
   10    15        FETCH_DIM_R                                      ~16     !5, 0
         16        INIT_ARRAY                                       ~17     ~16, 'sku'
   11    17        FETCH_DIM_R                                      ~18     !5, 1
         18        ADD_ARRAY_ELEMENT                                ~17     ~18, 'qty'
    9    19        ASSIGN_DIM                                               !2
   11    20        OP_DATA                                                  ~17
    6    21      > JMP                                                      ->8
         22    >   FE_FREE                                                  $10
   15    23        INIT_FCALL                                               'json_encode'
         24        SEND_VAR                                                 !2
         25        SEND_VAL                                                 128
         26        DO_ICALL                                         $19     
         27        ECHO                                                     $19
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.42 ms | 1400 KiB | 17 Q