3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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=['n1'=>'foo', 'n4'=>'bar', 'n6'=>'baz', 'n7'=>'baz', 'n2'=>'efg', 'n3'=>'kdjh']; var_dump(reorderArray($array, 'n1'));
based on Ai1fd
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/CHUED
function name:  (null)
number of ops:  10
compiled vars:  !0 = $array
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   NOP                                                      
  17     1        ASSIGN                                                   !0, <array>
  18     2        INIT_FCALL                                               'var_dump'
         3        INIT_FCALL                                               'reorderarray'
         4        SEND_VAR                                                 !0
         5        SEND_VAL                                                 'n1'
         6        DO_FCALL                                      0  $2      
         7        SEND_VAR                                                 $2
         8        DO_ICALL                                                 
         9      > RETURN                                                   1

Function reorderarray:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
Jump found. Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
Jump found. Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
Jump found. Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
Jump found. Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 15
Branch analysis from position: 9
Branch analysis from position: 16
Jump found. Position 1 = -2
Branch analysis from position: 16
filename:       /in/CHUED
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
        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 7.2.0