3v4l.org

run code in 300+ PHP versions simultaneously
<?php $raw = <<< 'TEXT' FIRSTNAME=firstname NAME=lastname STREET=street adress CITY=cityname ZIP=zipcode COUNTRY=country ISOCOUNTRY=US EMAIL=email@domene.com MOBILENO=123456789 USERNO=somenumber [PRODUCT] QTY=2 ALPROJECTID=1123208 PRICE=134,00 DESCRIPTION=product1 ARTNO=1 [PRODUCT] QTY=1 ALPROJECTID=9563214 PRICE=64,00 DESCRIPTION=product2 ARTNO=2 TEXT; //replace [PRODUCT] with [PRODUCT_1], [PRODUCT_2]... $raw = preg_replace_callback( '/\[PRODUCT\]/', function() {static $i=0; return '[PRODUCT_'.$i++.']';} ,$raw, -1, $count); //parse string into an array $data = parse_ini_string($raw,true); //extract the products into their own array. This assumes that //[PRODUCT] sections are always at the end of the file $products = array_values(array_splice($data,$count*-1)); //Build the final array $data = $data + ['PRODUCTS'=>$products]; echo "There are $count products \n\n"; print_r($data);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4rCWS
function name:  (null)
number of ops:  35
compiled vars:  !0 = $raw, !1 = $count, !2 = $data, !3 = $products
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'FIRSTNAME%3Dfirstname%0ANAME%3Dlastname%0ASTREET%3Dstreet+adress%0ACITY%3Dcityname%0AZIP%3Dzipcode%0ACOUNTRY%3Dcountry%0AISOCOUNTRY%3DUS%0AEMAIL%3Demail%40domene.com%0AMOBILENO%3D123456789%0AUSERNO%3Dsomenumber%0A%0A%5BPRODUCT%5D%0AQTY%3D2%0AALPROJECTID%3D1123208%0APRICE%3D134%2C00%0ADESCRIPTION%3Dproduct1%0AARTNO%3D1%0A%0A%5BPRODUCT%5D%0AQTY%3D1%0AALPROJECTID%3D9563214%0APRICE%3D64%2C00%0ADESCRIPTION%3Dproduct2%0AARTNO%3D2'
   30     1        INIT_FCALL                                               'preg_replace_callback'
   31     2        SEND_VAL                                                 '%2F%5C%5BPRODUCT%5C%5D%2F'
   32     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F4rCWS%3A32%240'
          4        SEND_VAL                                                 ~5
   33     5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 -1
          7        SEND_REF                                                 !1
          8        DO_ICALL                                         $6      
   30     9        ASSIGN                                                   !0, $6
   36    10        INIT_FCALL                                               'parse_ini_string'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $8      
         14        ASSIGN                                                   !2, $8
   40    15        INIT_FCALL                                               'array_values'
         16        INIT_FCALL                                               'array_splice'
         17        SEND_REF                                                 !2
         18        MUL                                              ~10     !1, -1
         19        SEND_VAL                                                 ~10
         20        DO_ICALL                                         $11     
         21        SEND_VAR                                                 $11
         22        DO_ICALL                                         $12     
         23        ASSIGN                                                   !3, $12
   43    24        INIT_ARRAY                                       ~14     !3, 'PRODUCTS'
         25        ADD                                              ~15     !2, ~14
         26        ASSIGN                                                   !2, ~15
   44    27        ROPE_INIT                                     3  ~18     'There+are+'
         28        ROPE_ADD                                      1  ~18     ~18, !1
         29        ROPE_END                                      2  ~17     ~18, '+products+%0A%0A'
         30        ECHO                                                     ~17
   45    31        INIT_FCALL                                               'print_r'
         32        SEND_VAR                                                 !2
         33        DO_ICALL                                                 
         34      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F4rCWS%3A32%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4rCWS
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   BIND_STATIC                                              !0
          1        POST_INC                                         ~1      !0
          2        CONCAT                                           ~2      '%5BPRODUCT_', ~1
          3        CONCAT                                           ~3      ~2, '%5D'
          4      > RETURN                                                   ~3
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F4rCWS%3A32%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.24 ms | 1405 KiB | 23 Q