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' => 256, 'region' => 257, 'region_id' => 258, 'city' => 259, 'city_id' => 260]; $index = 0; $result = []; foreach ($array as $k => $v) { if ( isset($ordered_keys[$k]) ) { $result[$k] = $ordered_keys[$k]; if ( $index < 255 ) $index = 512; } else { $result[$k] = $index++; } } asort($result); foreach($result as $k => $v) { $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 = 20
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 15
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 20
filename:       /in/fYFG5
function name:  (null)
number of ops:  36
compiled vars:  !0 = $array, !1 = $ordered_keys, !2 = $index, !3 = $result, !4 = $v, !5 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, <array>
   18     2        ASSIGN                                                   !2, 0
   20     3        ASSIGN                                                   !3, <array>
   22     4      > FE_RESET_R                                       $10     !0, ->20
          5    > > FE_FETCH_R                                       ~11     $10, !4, ->20
          6    >   ASSIGN                                                   !5, ~11
   23     7        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !5
          8      > JMPZ                                                     ~13, ->16
   24     9    >   FETCH_DIM_R                                      ~15     !1, !5
         10        ASSIGN_DIM                                               !3, !5
         11        OP_DATA                                                  ~15
   25    12        IS_SMALLER                                               !2, 255
         13      > JMPZ                                                     ~16, ->15
         14    >   ASSIGN                                                   !2, 512
   23    15    > > JMP                                                      ->19
   27    16    >   POST_INC                                         ~19     !2
         17        ASSIGN_DIM                                               !3, !5
         18        OP_DATA                                                  ~19
   22    19    > > JMP                                                      ->5
         20    >   FE_FREE                                                  $10
   31    21        INIT_FCALL                                               'asort'
         22        SEND_REF                                                 !3
         23        DO_ICALL                                                 
   33    24      > FE_RESET_R                                       $21     !3, ->31
         25    > > FE_FETCH_R                                       ~22     $21, !4, ->31
         26    >   ASSIGN                                                   !5, ~22
   34    27        FETCH_DIM_R                                      ~25     !0, !5
         28        ASSIGN_DIM                                               !3, !5
         29        OP_DATA                                                  ~25
   33    30      > JMP                                                      ->25
         31    >   FE_FREE                                                  $21
   37    32        INIT_FCALL                                               'print_r'
         33        SEND_VAR                                                 !3
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.55 ms | 1022 KiB | 15 Q