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", "Lifetime test Warranty test2" ]; $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); $warranty = array_filter($parts, function ($x) { return strtolower($x) === 'warranty'; }); if (count($warranty) > 0) { $wkey = key($warranty); unset($parts[$wkey]); $result[reset($warranty)] = implode(' ', $parts); continue; } $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 = 90
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 90
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 = 89
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 79
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 89
Branch analysis from position: 90
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 90
filename:       /in/Zvi0X
function name:  (null)
number of ops:  95
compiled vars:  !0 = $items, !1 = $result, !2 = $item, !3 = $res, !4 = $key, !5 = $parts, !6 = $warranty, !7 = $wkey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   14     1        ASSIGN                                                   !1, <array>
   16     2      > FE_RESET_R                                       $10     !0, ->90
          3    > > FE_FETCH_R                                               $10, !2, ->90
   17     4    >   INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '%3A'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $11     
          8        ASSIGN                                                   !3, $11
   18     9        COUNT                                            ~13     !3
         10        IS_SMALLER                                               1, ~13
         11      > JMPZ                                                     ~14, ->24
   19    12    >   FETCH_DIM_R                                      ~15     !3, 0
         13        ASSIGN                                                   !4, ~15
   20    14        INIT_FCALL                                               'array_shift'
         15        SEND_REF                                                 !3
         16        DO_ICALL                                                 
   21    17        INIT_FCALL                                               'implode'
         18        SEND_VAL                                                 '%3A'
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $19     
         21        ASSIGN_DIM                                               !1, !4
         22        OP_DATA                                                  $19
   22    23      > JMP                                                      ->3
   24    24    >   INIT_FCALL                                               'is_numeric'
         25        FETCH_DIM_R                                      ~20     !2, 0
         26        SEND_VAL                                                 ~20
         27        DO_ICALL                                         $21     
         28      > JMPZ                                                     $21, ->45
   25    29    >   INIT_FCALL                                               'explode'
         30        SEND_VAL                                                 '+'
         31        SEND_VAR                                                 !2
         32        DO_ICALL                                         $22     
         33        ASSIGN                                                   !5, $22
   26    34        INIT_FCALL                                               'array_pop'
         35        SEND_REF                                                 !5
         36        DO_ICALL                                         $24     
         37        ASSIGN                                                   !4, $24
   27    38        INIT_FCALL                                               'implode'
         39        SEND_VAL                                                 '+'
         40        SEND_VAR                                                 !5
         41        DO_ICALL                                         $27     
         42        ASSIGN_DIM                                               !1, !4
         43        OP_DATA                                                  $27
   28    44      > JMP                                                      ->3
   31    45    >   INIT_FCALL                                               'ctype_alpha'
         46        FETCH_DIM_R                                      ~28     !2, 0
         47        SEND_VAL                                                 ~28
         48        DO_ICALL                                         $29     
         49      > JMPZ                                                     $29, ->89
   32    50    >   INIT_FCALL                                               'explode'
         51        SEND_VAL                                                 '+'
         52        SEND_VAR                                                 !2
         53        DO_ICALL                                         $30     
         54        ASSIGN                                                   !5, $30
   33    55        INIT_FCALL                                               'array_filter'
         56        SEND_VAR                                                 !5
         57        DECLARE_LAMBDA_FUNCTION                          ~32     [0]
   35    58        SEND_VAL                                                 ~32
   33    59        DO_ICALL                                         $33     
         60        ASSIGN                                                   !6, $33
   36    61        COUNT                                            ~35     !6
         62        IS_SMALLER                                               0, ~35
         63      > JMPZ                                                     ~36, ->79
   37    64    >   INIT_FCALL                                               'key'
         65        SEND_VAR                                                 !6
         66        DO_ICALL                                         $37     
         67        ASSIGN                                                   !7, $37
   38    68        UNSET_DIM                                                !5, !7
   39    69        INIT_FCALL                                               'reset'
         70        SEND_REF                                                 !6
         71        DO_ICALL                                         $39     
         72        INIT_FCALL                                               'implode'
         73        SEND_VAL                                                 '+'
         74        SEND_VAR                                                 !5
         75        DO_ICALL                                         $41     
         76        ASSIGN_DIM                                               !1, $39
         77        OP_DATA                                                  $41
   40    78      > JMP                                                      ->3
   42    79    >   INIT_FCALL                                               'array_shift'
         80        SEND_REF                                                 !5
         81        DO_ICALL                                         $42     
         82        ASSIGN                                                   !4, $42
   43    83        INIT_FCALL                                               'implode'
         84        SEND_VAL                                                 '+'
         85        SEND_VAR                                                 !5
         86        DO_ICALL                                         $45     
         87        ASSIGN_DIM                                               !1, !4
         88        OP_DATA                                                  $45
   16    89    > > JMP                                                      ->3
         90    >   FE_FREE                                                  $10
   47    91        INIT_FCALL                                               'print_r'
         92        SEND_VAR                                                 !1
         93        DO_ICALL                                                 
         94      > 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/Zvi0X
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        INIT_FCALL                                               'strtolower'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        IS_IDENTICAL                                     ~2      $1, 'warranty'
          5      > RETURN                                                   ~2
   35     6*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.98 ms | 1031 KiB | 24 Q