3v4l.org

run code in 300+ PHP versions simultaneously
<?php function reorderArray($array, $key) { if(!array_key_exists($key, $array)) { return $array; } $one = []; foreach($array as $k=>$v) { if($k===$key) { break; } $one[$k] = $v; unset($array[$k]); } return array_merge($array, $one); } $array=[1=>'foo', 4=>'bar', 9=>'baz', 'test'=>51]; var_dump(reorderArray($array, 9)); var_dump(reorderArray($array, 'test'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YLcUj
function name:  (null)
number of ops:  16
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
   22     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'reorderarray'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 9
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
   23     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'reorderarray'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 'test'
         12        DO_FCALL                                      0  $4      
         13        SEND_VAR                                                 $4
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Function reorderarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 17
Branch analysis from position: 17
filename:       /in/YLcUj
function name:  reorderArray
number of ops:  24
compiled vars:  !0 = $array, !1 = $key, !2 = $one, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ARRAY_KEY_EXISTS                                 ~5      !1, !0
          3        BOOL_NOT                                         ~6      ~5
          4      > JMPZ                                                     ~6, ->6
    6     5    > > RETURN                                                   !0
    8     6    >   ASSIGN                                                   !2, <array>
    9     7      > FE_RESET_R                                       $8      !0, ->17
          8    > > FE_FETCH_R                                       ~9      $8, !3, ->17
          9    >   ASSIGN                                                   !4, ~9
   11    10        IS_IDENTICAL                                             !4, !1
         11      > JMPZ                                                     ~11, ->13
   13    12    > > JMP                                                      ->17
   15    13    >   ASSIGN_DIM                                               !2, !4
         14        OP_DATA                                                  !3
   16    15        UNSET_DIM                                                !0, !4
    9    16      > JMP                                                      ->8
         17    >   FE_FREE                                                  $8
   18    18        INIT_FCALL                                               'array_merge'
         19        SEND_VAR                                                 !0
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                         $13     
         22      > RETURN                                                   $13
   19    23*     > RETURN                                                   null

End of function reorderarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
197.02 ms | 1407 KiB | 19 Q