3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = [ "3000mAh battery", "charges 1 smartphone", "input: 5W (5V, 1A) micro USB port", "output: Micro USB cable: 7.5W (5V, 1.5A)", "recharge time 3-4 hours", "includes Micro USB cable", "1-Year Limited Warranty" ]; $result = []; foreach ($items as $item) { $res = explode(':', $item); if (count($res) > 1) { $key = $res[0]; array_shift($res); $result[$key] = implode(':', $res); continue; } if (is_numeric($item[0])) { $parts = (explode(' ', $item)); $key = array_pop($parts); $result[$key] = implode(' ', $parts); continue; } if (ctype_alpha ($item[0])) { $parts = explode(' ', $item); $key = array_shift($parts); $result[$key] = implode(' ', $parts); } } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 66
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 66
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 45
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 65
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 65
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
filename:       /in/CbnZN
function name:  (null)
number of ops:  71
compiled vars:  !0 = $items, !1 = $result, !2 = $item, !3 = $res, !4 = $key, !5 = $parts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   13     1        ASSIGN                                                   !1, <array>
   15     2      > FE_RESET_R                                       $8      !0, ->66
          3    > > FE_FETCH_R                                               $8, !2, ->66
   16     4    >   INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '%3A'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $9      
          8        ASSIGN                                                   !3, $9
   17     9        COUNT                                            ~11     !3
         10        IS_SMALLER                                               1, ~11
         11      > JMPZ                                                     ~12, ->24
   18    12    >   FETCH_DIM_R                                      ~13     !3, 0
         13        ASSIGN                                                   !4, ~13
   19    14        INIT_FCALL                                               'array_shift'
         15        SEND_REF                                                 !3
         16        DO_ICALL                                                 
   20    17        INIT_FCALL                                               'implode'
         18        SEND_VAL                                                 '%3A'
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $17     
         21        ASSIGN_DIM                                               !1, !4
         22        OP_DATA                                                  $17
   21    23      > JMP                                                      ->3
   23    24    >   INIT_FCALL                                               'is_numeric'
         25        FETCH_DIM_R                                      ~18     !2, 0
         26        SEND_VAL                                                 ~18
         27        DO_ICALL                                         $19     
         28      > JMPZ                                                     $19, ->45
   24    29    >   INIT_FCALL                                               'explode'
         30        SEND_VAL                                                 '+'
         31        SEND_VAR                                                 !2
         32        DO_ICALL                                         $20     
         33        ASSIGN                                                   !5, $20
   25    34        INIT_FCALL                                               'array_pop'
         35        SEND_REF                                                 !5
         36        DO_ICALL                                         $22     
         37        ASSIGN                                                   !4, $22
   26    38        INIT_FCALL                                               'implode'
         39        SEND_VAL                                                 '+'
         40        SEND_VAR                                                 !5
         41        DO_ICALL                                         $25     
         42        ASSIGN_DIM                                               !1, !4
         43        OP_DATA                                                  $25
   27    44      > JMP                                                      ->3
   29    45    >   INIT_FCALL                                               'ctype_alpha'
         46        FETCH_DIM_R                                      ~26     !2, 0
         47        SEND_VAL                                                 ~26
         48        DO_ICALL                                         $27     
         49      > JMPZ                                                     $27, ->65
   30    50    >   INIT_FCALL                                               'explode'
         51        SEND_VAL                                                 '+'
         52        SEND_VAR                                                 !2
         53        DO_ICALL                                         $28     
         54        ASSIGN                                                   !5, $28
   31    55        INIT_FCALL                                               'array_shift'
         56        SEND_REF                                                 !5
         57        DO_ICALL                                         $30     
         58        ASSIGN                                                   !4, $30
   32    59        INIT_FCALL                                               'implode'
         60        SEND_VAL                                                 '+'
         61        SEND_VAR                                                 !5
         62        DO_ICALL                                         $33     
         63        ASSIGN_DIM                                               !1, !4
         64        OP_DATA                                                  $33
   15    65    > > JMP                                                      ->3
         66    >   FE_FREE                                                  $8
   36    67        INIT_FCALL                                               'print_r'
         68        SEND_VAR                                                 !1
         69        DO_ICALL                                                 
         70      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.8 ms | 1022 KiB | 20 Q