3v4l.org

run code in 300+ PHP versions simultaneously
<?php function reorderArray($array, $key) { $found = false; foreach($array as $k=>$v) { $found = $found || $k===$key; if(!$found) { unset($array[$k]); $array[$k] = $v; } } return $array; } $array=[1=>'foo', 4=>'bar', 9=>'baz', 'test'=>51]; var_dump(reorderArray($array, 9)); var_dump(reorderArray($array, 'test')); var_dump(reorderArray($array, 'no_such_key'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sRWVK
function name:  (null)
number of ops:  23
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, <array>
   18     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                                                 
   19     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                                                 
   20    15        INIT_FCALL                                               'var_dump'
         16        INIT_FCALL                                               'reorderarray'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 'no_such_key'
         19        DO_FCALL                                      0  $6      
         20        SEND_VAR                                                 $6
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

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

End of function reorderarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.52 ms | 1403 KiB | 18 Q