3v4l.org

run code in 300+ PHP versions simultaneously
<?php function algorithm_a() { $data = [ 'city' => 'Lexington', 'name' => 'Mike Tyson', 'occupation' => 'Hot Dog Vendor', 'state' => 'KY', 'address' => '1009 Nicholasville Road', 'ZIP' => '40526' ]; $order = [ 'name', 'city', 'state' ]; $filtered = array_intersect_key( $data, array_flip($order) ); $ordered = array_merge( array_flip($order), $filtered ); return $ordered; } function algorithm_b() { $data = [ 'city' => 'Lexington', 'name' => 'Mike Tyson', 'occupation' => 'Hot Dog Vendor', 'state' => 'KY', 'address' => '1009 Nicholasville Road', 'ZIP' => '40526' ]; $order = [ 'name', 'city', 'state' ]; $result = array(); foreach($order as $column_name) { $result[$column_name] = $data[$column_name]; } return $result; } $result = algorithm_b(); var_dump($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/65SJu
function name:  (null)
number of ops:  7
compiled vars:  !0 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   INIT_FCALL                                               'algorithm_b'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   60     3        INIT_FCALL                                               'var_dump'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function algorithm_a:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/65SJu
function name:  algorithm_a
number of ops:  20
compiled vars:  !0 = $data, !1 = $order, !2 = $filtered, !3 = $ordered
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   ASSIGN                                                   !0, <array>
   15     1        ASSIGN                                                   !1, <array>
   21     2        INIT_FCALL                                               'array_intersect_key'
   22     3        SEND_VAR                                                 !0
   23     4        INIT_FCALL                                               'array_flip'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $6      
          7        SEND_VAR                                                 $6
          8        DO_ICALL                                         $7      
   21     9        ASSIGN                                                   !2, $7
   26    10        INIT_FCALL                                               'array_merge'
   27    11        INIT_FCALL                                               'array_flip'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $9      
         14        SEND_VAR                                                 $9
   28    15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $10     
   26    17        ASSIGN                                                   !3, $10
   31    18      > RETURN                                                   !3
   32    19*     > RETURN                                                   null

End of function algorithm_a

Function algorithm_b:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/65SJu
function name:  algorithm_b
number of ops:  12
compiled vars:  !0 = $data, !1 = $order, !2 = $result, !3 = $column_name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ASSIGN                                                   !0, <array>
   45     1        ASSIGN                                                   !1, <array>
   51     2        ASSIGN                                                   !2, <array>
   52     3      > FE_RESET_R                                       $7      !1, ->9
          4    > > FE_FETCH_R                                               $7, !3, ->9
   53     5    >   FETCH_DIM_R                                      ~9      !0, !3
          6        ASSIGN_DIM                                               !2, !3
          7        OP_DATA                                                  ~9
   52     8      > JMP                                                      ->4
          9    >   FE_FREE                                                  $7
   56    10      > RETURN                                                   !2
   57    11*     > RETURN                                                   null

End of function algorithm_b

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.11 ms | 1394 KiB | 22 Q