3v4l.org

run code in 300+ PHP versions simultaneously
<?php function remap($e) { $elements = array( 1 => 'first_name', 2 => 'city', 3 => 'email', 4 => 'phone' ); $key = isset($elements[$e['element_id']]) ? $elements[$e['element_id']]: 'unknown'; return array($key => $e['value']); } $input[] = array('entry_id' => 33, 'element_id' => 1, 'value' => 'Fred'); $input[] = array('entry_id' => 33, 'element_id' => 2, 'value' => 'Phoenix'); $input[] = array('entry_id' => 33, 'element_id' => 3, 'value' => 'fred@test.com'); $input[] = array('entry_id' => 33, 'element_id' => 99, 'value' => 'Something else entirely'); $output = array(); foreach(array_map('remap', $input, $elements) as $key => $value) { $output[$key] = $value; }; var_dump($output);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/nNIpf
function name:  (null)
number of ops:  25
compiled vars:  !0 = $input, !1 = $output, !2 = $elements, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN_DIM                                               !0
          1        OP_DATA                                                  <array>
   18     2        ASSIGN_DIM                                               !0
          3        OP_DATA                                                  <array>
   19     4        ASSIGN_DIM                                               !0
          5        OP_DATA                                                  <array>
   20     6        ASSIGN_DIM                                               !0
          7        OP_DATA                                                  <array>
   22     8        ASSIGN                                                   !1, <array>
   23     9        INIT_FCALL                                               'array_map'
         10        SEND_VAL                                                 'remap'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $10     
         14      > FE_RESET_R                                       $11     $10, ->20
         15    > > FE_FETCH_R                                       ~12     $11, !3, ->20
         16    >   ASSIGN                                                   !4, ~12
   24    17        ASSIGN_DIM                                               !1, !4
         18        OP_DATA                                                  !3
   23    19      > JMP                                                      ->15
         20    >   FE_FREE                                                  $11
   27    21        INIT_FCALL                                               'var_dump'
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Function remap:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nNIpf
function name:  remap
number of ops:  15
compiled vars:  !0 = $e, !1 = $elements, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        ASSIGN                                                   !1, <array>
   12     2        FETCH_DIM_R                                      ~4      !0, 'element_id'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~4
          4      > JMPZ                                                     ~5, ->9
          5    >   FETCH_DIM_R                                      ~6      !0, 'element_id'
          6        FETCH_DIM_R                                      ~7      !1, ~6
          7        QM_ASSIGN                                        ~8      ~7
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~8      'unknown'
         10    >   ASSIGN                                                   !2, ~8
   13    11        FETCH_DIM_R                                      ~10     !0, 'value'
         12        INIT_ARRAY                                       ~11     ~10, !2
         13      > RETURN                                                   ~11
   14    14*     > RETURN                                                   null

End of function remap

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.18 ms | 1405 KiB | 17 Q