3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ (object)['key' => 'sample', 'startYear' => '2000', 'endYear' => '2015'], (object)['key' => 'second_sample', 'startYear' => '1985', 'endYear' => '1991'] ]; $result = []; foreach ($array as $object) { ['key' => $key, 'startYear' => $result[$key]['startYear'], 'endYear' => $result[$key]['endYear']] = (array)$object; } var_export($result); echo "\n---\n"; var_export( array_reduce( $array, function($result, $object) { ['key' => $key, 'startYear' => $result[$key]['startYear'], 'endYear' => $result[$key]['endYear']] = (array)$object; return $result; }, [] ) );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 21
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 21
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/0Xtli
function name:  (null)
number of ops:  36
compiled vars:  !0 = $array, !1 = $result, !2 = $object, !3 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   CAST                                              8  ~4      <array>
          1        INIT_ARRAY                                           ~5      ~4
          2        CAST                                              8  ~6      <array>
          3        ADD_ARRAY_ELEMENT                                    ~5      ~6
    3     4        ASSIGN                                                       !0, ~5
    8     5        ASSIGN                                                       !1, <array>
    9     6      > FE_RESET_R                                           $9      !0, ->21
          7    > > FE_FETCH_R                                                   $9, !2, ->21
   10     8    >   CAST                                              7  ~10     !2
          9        FETCH_LIST_R                                         $11     ~10, 'key'
         10        ASSIGN                                                       !3, $11
         11        FETCH_LIST_R                                         $13     ~10, 'startYear'
         12        FETCH_DIM_W                                          $14     !1, !3
         13        ASSIGN_DIM                                                   $14, 'startYear'
         14        OP_DATA                                                      $13
         15        FETCH_LIST_R                                         $16     ~10, 'endYear'
         16        FETCH_DIM_W                                          $17     !1, !3
         17        ASSIGN_DIM                                                   $17, 'endYear'
         18        OP_DATA                                                      $16
         19        FREE                                                         ~10
    9    20      > JMP                                                          ->7
         21    >   FE_FREE                                                      $9
   13    22        INIT_FCALL                                                   'var_export'
         23        SEND_VAR                                                     !1
         24        DO_ICALL                                                     
   15    25        ECHO                                                         '%0A---%0A'
   17    26        INIT_FCALL                                                   'var_export'
   18    27        INIT_FCALL                                                   'array_reduce'
   19    28        SEND_VAR                                                     !0
   20    29        DECLARE_LAMBDA_FUNCTION                              ~20     [0]
   23    30        SEND_VAL                                                     ~20
   24    31        SEND_VAL                                                     <array>
   18    32        DO_ICALL                                             $21     
   24    33        SEND_VAR                                                     $21
   17    34        DO_ICALL                                                     
   26    35      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Xtli
function name:  {closure:/in/0Xtli:20}
number of ops:  16
compiled vars:  !0 = $result, !1 = $object, !2 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   21     2        CAST                                              7  ~3      !1
          3        FETCH_LIST_R                                         $4      ~3, 'key'
          4        ASSIGN                                                       !2, $4
          5        FETCH_LIST_R                                         $6      ~3, 'startYear'
          6        FETCH_DIM_W                                          $7      !0, !2
          7        ASSIGN_DIM                                                   $7, 'startYear'
          8        OP_DATA                                                      $6
          9        FETCH_LIST_R                                         $9      ~3, 'endYear'
         10        FETCH_DIM_W                                          $10     !0, !2
         11        ASSIGN_DIM                                                   $10, 'endYear'
         12        OP_DATA                                                      $9
         13        FREE                                                         ~3
   22    14      > RETURN                                                       !0
   23    15*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.95 ms | 2144 KiB | 15 Q