3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ "key 1" => ['more data' ], "key 2" => [ 'even more data' ], "key 3" => [ 'some data' ], "key 4" => [ 'where is the data' ] ]; $key = 'key 3'; $moved = move_to_first_in_array($array , 'key 3'); print_r($moved); function move_to_first_in_array($array, $key) { return [$key => $array[$key]] + $array; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZQV2i
function name:  (null)
number of ops:  11
compiled vars:  !0 = $array, !1 = $key, !2 = $moved
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
    9     1        ASSIGN                                                       !1, 'key+3'
   10     2        INIT_FCALL_BY_NAME                                           'move_to_first_in_array'
          3        SEND_VAR_EX                                                  !0
          4        SEND_VAL_EX                                                  'key+3'
          5        DO_FCALL                                          0  $5      
          6        ASSIGN                                                       !2, $5
   12     7        INIT_FCALL                                                   'print_r'
          8        SEND_VAR                                                     !2
          9        DO_ICALL                                                     
   16    10      > RETURN                                                       1

Function move_to_first_in_array:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZQV2i
function name:  move_to_first_in_array
number of ops:  7
compiled vars:  !0 = $array, !1 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   15     2        FETCH_DIM_R                                          ~2      !0, !1
          3        INIT_ARRAY                                           ~3      ~2, !1
          4        ADD                                                  ~4      ~3, !0
          5      > RETURN                                                       ~4
   16     6*     > RETURN                                                       null

End of function move_to_first_in_array

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
214.11 ms | 2133 KiB | 14 Q