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']; $flag = true; $result = []; foreach ($array as $k=>$v) { if ($flag && in_array($k, $ordered_keys)) { $flag = false; foreach ($ordered_keys as $key) { $result[$key] = $array[$key]; } } else { $result[$k] = $array[$k]; } } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 27
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 27
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 = 23
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 21
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 13
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/uf2BB
function name:  (null)
number of ops:  32
compiled vars:  !0 = $array, !1 = $ordered_keys, !2 = $flag, !3 = $result, !4 = $v, !5 = $k, !6 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, <array>
   18     2        ASSIGN                                                   !2, <true>
   19     3        ASSIGN                                                   !3, <array>
   21     4      > FE_RESET_R                                       $11     !0, ->27
          5    > > FE_FETCH_R                                       ~12     $11, !4, ->27
          6    >   ASSIGN                                                   !5, ~12
   22     7      > JMPZ_EX                                          ~14     !2, ->13
          8    >   INIT_FCALL                                               'in_array'
          9        SEND_VAR                                                 !5
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $15     
         12        BOOL                                             ~14     $15
         13    > > JMPZ                                                     ~14, ->23
   23    14    >   ASSIGN                                                   !2, <false>
   24    15      > FE_RESET_R                                       $17     !1, ->21
         16    > > FE_FETCH_R                                               $17, !6, ->21
   25    17    >   FETCH_DIM_R                                      ~19     !0, !6
         18        ASSIGN_DIM                                               !3, !6
         19        OP_DATA                                                  ~19
   24    20      > JMP                                                      ->16
         21    >   FE_FREE                                                  $17
   22    22      > JMP                                                      ->26
   28    23    >   FETCH_DIM_R                                      ~21     !0, !5
         24        ASSIGN_DIM                                               !3, !5
         25        OP_DATA                                                  ~21
   21    26    > > JMP                                                      ->5
         27    >   FE_FREE                                                  $11
   32    28        INIT_FCALL                                               'print_r'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.9 ms | 1022 KiB | 15 Q