3v4l.org

run code in 300+ PHP versions simultaneously
<?php function change_key( $array, $old_key, $new_key) { if( ! array_key_exists( $old_key, $array ) ) return $array; $keys = array_keys( $array ); $keys[ array_search( $old_key, $keys ) ] = $new_key; return array_combine( $keys, $array ); } $array = array( 'a' => 1, 'b' => 2, 'c' => 3 ); var_dump($array); $array = change_key($array, 'b', 'd'); var_dump($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CVadG
function name:  (null)
number of ops:  14
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, <array>
   20     1        INIT_FCALL                                               'var_dump'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
   22     4        INIT_FCALL                                               'change_key'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 'b'
          7        SEND_VAL                                                 'd'
          8        DO_FCALL                                      0  $3      
          9        ASSIGN                                                   !0, $3
   24    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function change_key:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CVadG
function name:  change_key
number of ops:  23
compiled vars:  !0 = $array, !1 = $old_key, !2 = $new_key, !3 = $keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    5     3        ARRAY_KEY_EXISTS                                 ~4      !1, !0
          4        BOOL_NOT                                         ~5      ~4
          5      > JMPZ                                                     ~5, ->7
    6     6    > > RETURN                                                   !0
    8     7    >   INIT_FCALL                                               'array_keys'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !3, $6
    9    11        INIT_FCALL                                               'array_search'
         12        SEND_VAR                                                 !1
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $8      
         15        ASSIGN_DIM                                               !3, $8
         16        OP_DATA                                                  !2
   11    17        INIT_FCALL                                               'array_combine'
         18        SEND_VAR                                                 !3
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $10     
         21      > RETURN                                                   $10
   12    22*     > RETURN                                                   null

End of function change_key

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.39 ms | 1390 KiB | 22 Q