3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'some' => 'somevalue', 'some2'=>'some2value', 'some1' => 'some1value', 'id' => 123 ]; $pattern = [ 'some2', 'id', 'some1', 'some' ]; function sortByTemplate($array, $pattern) { $result = []; foreach (array_flip($pattern) as $k => $v) { if (isset($array[$k])) { $result[$k] = $array[$k]; } } return $result; } print_r(sortByTemplate($array, $pattern));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/U0Ala
function name:  (null)
number of ops:  10
compiled vars:  !0 = $array, !1 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   29     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'sortbytemplate'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function sortbytemplate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 14
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/U0Ala
function name:  sortByTemplate
number of ops:  18
compiled vars:  !0 = $array, !1 = $pattern, !2 = $result, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        ASSIGN                                                   !2, <array>
   20     3        INIT_FCALL                                               'array_flip'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $6      
          6      > FE_RESET_R                                       $7      $6, ->15
          7    > > FE_FETCH_R                                       ~8      $7, !3, ->15
          8    >   ASSIGN                                                   !4, ~8
   21     9        ISSET_ISEMPTY_DIM_OBJ                         0          !0, !4
         10      > JMPZ                                                     ~10, ->14
   22    11    >   FETCH_DIM_R                                      ~12     !0, !4
         12        ASSIGN_DIM                                               !2, !4
         13        OP_DATA                                                  ~12
   20    14    > > JMP                                                      ->7
         15    >   FE_FREE                                                  $7
   26    16      > RETURN                                                   !2
   27    17*     > RETURN                                                   null

End of function sortbytemplate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.72 ms | 1399 KiB | 18 Q