3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Пополнить справочник названиями полей. $fields=[4=>'value', 6=>'feedback', 11=>'city']; //Пополнить справочник значениями element_id с текстовыми значениями $text_fields = [6]; $src=[ [ 'entry_id' => 3, 'element_id' => 4, //Эта строка сериализована криво //'value' => 'a:2:{i:2;s:14:"Имя";i:4;s:18:"Фамилия";}' 'value' => 'a:2:{i:2;s:6:"Имя";i:4;s:14:"Фамилия";}' ], [ 'entry_id' => 3, 'element_id' => 6, 'value' => 'Тестовый отзыв' ], [ 'entry_id' => 3, 'element_id' => 11, 'value' => 'a:1:{i:2;s:16:"г. Москва";}' ], ]; $dst = []; foreach($src as $row){ $field = $fields[$row['element_id']]; if (in_array($row['element_id'], $text_fields)) { $dst[$row['entry_id']][$field] = $row['value']; } else { $dst[$row['entry_id']][$field] = implode(" ", unserialize($row['value'])); } } print_r($dst);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 34
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 34
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/fSE2r
function name:  (null)
number of ops:  39
compiled vars:  !0 = $fields, !1 = $text_fields, !2 = $src, !3 = $dst, !4 = $row, !5 = $field
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, <array>
   25     3        ASSIGN                                                   !3, <array>
   26     4      > FE_RESET_R                                       $10     !2, ->34
          5    > > FE_FETCH_R                                               $10, !4, ->34
   27     6    >   FETCH_DIM_R                                      ~11     !4, 'element_id'
          7        FETCH_DIM_R                                      ~12     !0, ~11
          8        ASSIGN                                                   !5, ~12
   28     9        INIT_FCALL                                               'in_array'
         10        FETCH_DIM_R                                      ~14     !4, 'element_id'
         11        SEND_VAL                                                 ~14
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $15     
         14      > JMPZ                                                     $15, ->21
   29    15    >   FETCH_DIM_R                                      ~16     !4, 'entry_id'
         16        FETCH_DIM_R                                      ~19     !4, 'value'
         17        FETCH_DIM_W                                      $17     !3, ~16
         18        ASSIGN_DIM                                               $17, !5
         19        OP_DATA                                                  ~19
   28    20      > JMP                                                      ->33
   31    21    >   FETCH_DIM_R                                      ~20     !4, 'entry_id'
         22        INIT_FCALL                                               'implode'
         23        SEND_VAL                                                 '+'
         24        INIT_FCALL                                               'unserialize'
         25        FETCH_DIM_R                                      ~23     !4, 'value'
         26        SEND_VAL                                                 ~23
         27        DO_ICALL                                         $24     
         28        SEND_VAR                                                 $24
         29        DO_ICALL                                         $25     
         30        FETCH_DIM_W                                      $21     !3, ~20
         31        ASSIGN_DIM                                               $21, !5
         32        OP_DATA                                                  $25
   26    33    > > JMP                                                      ->5
         34    >   FE_FREE                                                  $10
   35    35        INIT_FCALL                                               'print_r'
         36        SEND_VAR                                                 !3
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
130.12 ms | 1018 KiB | 17 Q