3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ //... 'name' => ['value' => 'Raj KB'], 'street' => ['value' => 'Street ABC'], 'city' => ['value' => 'Dubai'], 'country_id' => ['value' => 'UAE'], 'region' => ['value' => 'DXB'], 'region_id' => ['value' => 11], 'zip_code' => ['value' => 12345], 'city_id' => ['value' => 22], //... ]; $ordered_keys = ['country_id', 'region', 'region_id', 'city', 'city_id']; $keys = (function ($array, $ordered_keys) { $flag = true; foreach ($array as $key => $v) { if ( $flag && in_array($key, $ordered_keys) ) { yield from $ordered_keys; $flag = false; } yield $key; } })($array, $ordered_keys); $result = []; foreach($keys as $key) { $result[$key] = $array[$key]; } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/Q8eVk
function name:  (null)
number of ops:  20
compiled vars:  !0 = $array, !1 = $ordered_keys, !2 = $keys, !3 = $result, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, <array>
   18     2        DECLARE_LAMBDA_FUNCTION                          ~7      [0]
   27     3        INIT_DYNAMIC_CALL                                        ~7
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $8      
   18     7        ASSIGN                                                   !2, $8
   29     8        ASSIGN                                                   !3, <array>
   31     9      > FE_RESET_R                                       $11     !2, ->15
         10    > > FE_FETCH_R                                               $11, !4, ->15
   32    11    >   FETCH_DIM_R                                      ~13     !0, !4
         12        ASSIGN_DIM                                               !3, !4
         13        OP_DATA                                                  ~13
   31    14      > JMP                                                      ->10
         15    >   FE_FREE                                                  $11
   35    16        INIT_FCALL                                               'print_r'
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                                 
         19      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 19
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 17
Branch analysis from position: 13
Branch analysis from position: 19
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 19
filename:       /in/Q8eVk
function name:  {closure}
number of ops:  21
compiled vars:  !0 = $array, !1 = $ordered_keys, !2 = $flag, !3 = $v, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
   19     3        ASSIGN                                                   !2, <true>
   20     4      > FE_RESET_R                                       $6      !0, ->19
          5    > > FE_FETCH_R                                       ~7      $6, !3, ->19
          6    >   ASSIGN                                                   !4, ~7
   21     7      > JMPZ_EX                                          ~9      !2, ->13
          8    >   INIT_FCALL                                               'in_array'
          9        SEND_VAR                                                 !4
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $10     
         12        BOOL                                             ~9      $10
         13    > > JMPZ                                                     ~9, ->17
   22    14    >   YIELD_FROM                                       ~11     !1
         15        FREE                                                     ~11
   23    16        ASSIGN                                                   !2, <false>
   25    17    >   YIELD                                                    !4
   20    18      > JMP                                                      ->5
         19    >   FE_FREE                                                  $6
   27    20      > GENERATOR_RETURN                                         

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.73 ms | 1022 KiB | 15 Q