3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a1 = [ 'from' => 'Paris', 'to' => 'Marseille', ]; $a2 = [ 'from' => 'Marseille', 'to' => 'Valencia', ]; $a3 = [ 'from' => 'Valencia', 'to' => 'Algiers', ]; $a4 = [ 'from' => 'Algiers', 'to' => 'Abu Dhabi', ]; $route = array($a4, $a3, $a1, $a2); $from = array_column($route, 'from'); $to = array_column($route, 'to'); $start = array_diff($from, $to); $sortedRoute = [$route[key($start)]]; $start = $route[key($start)]['to']; while (true) { $key = array_search($start, $from); if ($key === false) break; $sortedRoute[] = $route[$key]; $start = $route[$key]['to']; } var_dump($sortedRoute);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 37
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 45
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 37
Branch analysis from position: 52
Branch analysis from position: 37
filename:       /in/b6UiZ
function name:  (null)
number of ops:  56
compiled vars:  !0 = $a1, !1 = $a2, !2 = $a3, !3 = $a4, !4 = $route, !5 = $from, !6 = $to, !7 = $start, !8 = $sortedRoute, !9 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, <array>
   13     2        ASSIGN                                                   !2, <array>
   18     3        ASSIGN                                                   !3, <array>
   23     4        INIT_ARRAY                                       ~14     !3
          5        ADD_ARRAY_ELEMENT                                ~14     !2
          6        ADD_ARRAY_ELEMENT                                ~14     !0
          7        ADD_ARRAY_ELEMENT                                ~14     !1
          8        ASSIGN                                                   !4, ~14
   25     9        INIT_FCALL                                               'array_column'
         10        SEND_VAR                                                 !4
         11        SEND_VAL                                                 'from'
         12        DO_ICALL                                         $16     
         13        ASSIGN                                                   !5, $16
   26    14        INIT_FCALL                                               'array_column'
         15        SEND_VAR                                                 !4
         16        SEND_VAL                                                 'to'
         17        DO_ICALL                                         $18     
         18        ASSIGN                                                   !6, $18
   27    19        INIT_FCALL                                               'array_diff'
         20        SEND_VAR                                                 !5
         21        SEND_VAR                                                 !6
         22        DO_ICALL                                         $20     
         23        ASSIGN                                                   !7, $20
   29    24        INIT_FCALL                                               'key'
         25        SEND_VAR                                                 !7
         26        DO_ICALL                                         $22     
         27        FETCH_DIM_R                                      ~23     !4, $22
         28        INIT_ARRAY                                       ~24     ~23
         29        ASSIGN                                                   !8, ~24
   30    30        INIT_FCALL                                               'key'
         31        SEND_VAR                                                 !7
         32        DO_ICALL                                         $26     
         33        FETCH_DIM_R                                      ~27     !4, $26
         34        FETCH_DIM_R                                      ~28     ~27, 'to'
         35        ASSIGN                                                   !7, ~28
   31    36      > JMP                                                      ->51
   32    37    >   INIT_FCALL                                               'array_search'
         38        SEND_VAR                                                 !7
         39        SEND_VAR                                                 !5
         40        DO_ICALL                                         $30     
         41        ASSIGN                                                   !9, $30
   33    42        TYPE_CHECK                                    4          !9
         43      > JMPZ                                                     ~32, ->45
   34    44    > > JMP                                                      ->52
   35    45    >   FETCH_DIM_R                                      ~34     !4, !9
         46        ASSIGN_DIM                                               !8
         47        OP_DATA                                                  ~34
   36    48        FETCH_DIM_R                                      ~35     !4, !9
         49        FETCH_DIM_R                                      ~36     ~35, 'to'
         50        ASSIGN                                                   !7, ~36
   31    51    > > JMPNZ                                                    <true>, ->37
   39    52    >   INIT_FCALL                                               'var_dump'
         53        SEND_VAR                                                 !8
         54        DO_ICALL                                                 
         55      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.66 ms | 1023 KiB | 18 Q