3v4l.org

run code in 500+ PHP versions simultaneously
<?php $variations = [ "sku" => [ 0 => "dSADad", 1 => "ASDAF", 2 => "ASFAS", // ... ], "Price" => [ 0 => "1", 1 => "1", 2 => "1", // ... ], "Quantity" => [ 0 => "123", 1 => "123", 2 => "123434", // ... ], "attributes" => [ "Color" => [ 0 => "5", 1 => "4", 2 => "4", // ... ], "Size" => [ 0 => "3", 1 => "3", 2 => "2", // ... ], "Material" => [ 0 => "7", 1 => "7", 2 => "8", // ... ], ], ]; function extractVariation($variations, $key) { $variation = []; foreach ($variations as $property => $values) { if (isset($values[$key])) { $variation[$property] = $values[$key]; } else { $variation[$property] = extractVariation($values, $key); } } return $variation; } $newVariations = []; foreach ($variations['sku'] as $key => $sku) { $newVariations[] = extractVariation($variations, $key); } var_export($newVariations);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/l4gJQ
function name:  (null)
number of ops:  18
compiled vars:  !0 = $variations, !1 = $newVariations, !2 = $sku, !3 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   59     1        ASSIGN                                                       !1, <array>
   61     2        FETCH_DIM_R                                          ~6      !0, 'sku'
          3      > FE_RESET_R                                           $7      ~6, ->13
          4    > > FE_FETCH_R                                           ~8      $7, !2, ->13
          5    >   ASSIGN                                                       !3, ~8
   62     6        INIT_FCALL                                                   'extractvariation'
          7        SEND_VAR                                                     !0
          8        SEND_VAR                                                     !3
          9        DO_FCALL                                          0  $11     
         10        ASSIGN_DIM                                                   !1
         11        OP_DATA                                                      $11
   61    12      > JMP                                                          ->4
         13    >   FE_FREE                                                      $7
   65    14        INIT_FCALL                                                   'var_export'
         15        SEND_VAR                                                     !1
         16        DO_ICALL                                                     
         17      > RETURN                                                       1

Function extractvariation:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/l4gJQ
function name:  extractVariation
number of ops:  22
compiled vars:  !0 = $variations, !1 = $key, !2 = $variation, !3 = $values, !4 = $property
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   46     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   48     2        ASSIGN                                                       !2, <array>
   49     3      > FE_RESET_R                                           $6      !0, ->19
          4    > > FE_FETCH_R                                           ~7      $6, !3, ->19
          5    >   ASSIGN                                                       !4, ~7
   50     6        ISSET_ISEMPTY_DIM_OBJ                             0          !3, !1
          7      > JMPZ                                                         ~9, ->12
   51     8    >   FETCH_DIM_R                                          ~11     !3, !1
          9        ASSIGN_DIM                                                   !2, !4
         10        OP_DATA                                                      ~11
   50    11      > JMP                                                          ->18
   53    12    >   INIT_FCALL_BY_NAME                                           'extractVariation'
         13        SEND_VAR_EX                                                  !3
         14        SEND_VAR_EX                                                  !1
         15        DO_FCALL                                          0  $13     
         16        ASSIGN_DIM                                                   !2, !4
         17        OP_DATA                                                      $13
   49    18    > > JMP                                                          ->4
         19    >   FE_FREE                                                      $6
   56    20      > RETURN                                                       !2
   57    21*     > RETURN                                                       null

End of function extractvariation

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.17 ms | 1829 KiB | 15 Q