3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = Array ( 'package-name-1' => 'package1', 'package-serve-1' => 'sdasd', 'package-price-date-1' => '31-03-2020' , 'foodType-1-1' => 'Rice', 'foodTags-1-1' => 'rice', 'foodNotes-1-1' => 'notes', 'foodchoose-1-1' => 0, 'package-name-2' => 'package2', 'package-serve-2' => 'Leaf', 'package-price-date-2' => '12-08-2020', 'foodType-2-2' => 'rice1', 'foodTags-2-2' => 'rice1', 'foodNotes-2-2' => 'dasd', 'foodchoose-2-2' => 3, 'foodType-2-3' => 'rice2', 'foodTags-2-3' => 'rice2', 'foodNotes-2-3' => 'qwewe', 'foodchoose-2-3' => 0 ); $newArray = []; $k = 0; foreach($array as $key=>$value){ if(strpos($key,'package-name') !== false){ $explodedkeys = explode('-',$key); $id = end($explodedkeys); $k = $id-1; } $newArray[$k][$key] = $value; } print_r($newArray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 27
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 27
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 23
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/5eEkA
function name:  (null)
number of ops:  32
compiled vars:  !0 = $array, !1 = $newArray, !2 = $k, !3 = $value, !4 = $key, !5 = $explodedkeys, !6 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   25     1        ASSIGN                                                   !1, <array>
   27     2        ASSIGN                                                   !2, 0
   28     3      > FE_RESET_R                                       $10     !0, ->27
          4    > > FE_FETCH_R                                       ~11     $10, !3, ->27
          5    >   ASSIGN                                                   !4, ~11
   30     6        INIT_FCALL                                               'strpos'
          7        SEND_VAR                                                 !4
          8        SEND_VAL                                                 'package-name'
          9        DO_ICALL                                         $13     
         10        TYPE_CHECK                                  1018          $13
         11      > JMPZ                                                     ~14, ->23
   31    12    >   INIT_FCALL                                               'explode'
         13        SEND_VAL                                                 '-'
         14        SEND_VAR                                                 !4
         15        DO_ICALL                                         $15     
         16        ASSIGN                                                   !5, $15
   32    17        INIT_FCALL                                               'end'
         18        SEND_REF                                                 !5
         19        DO_ICALL                                         $17     
         20        ASSIGN                                                   !6, $17
   33    21        SUB                                              ~19     !6, 1
         22        ASSIGN                                                   !2, ~19
   35    23    >   FETCH_DIM_W                                      $21     !1, !2
         24        ASSIGN_DIM                                               $21, !4
         25        OP_DATA                                                  !3
   28    26      > JMP                                                      ->4
         27    >   FE_FREE                                                  $10
   38    28        INIT_FCALL                                               'print_r'
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.75 ms | 1004 KiB | 17 Q