3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cards = [ [ "from" => "Barcelona", "to" => "Gerona Airport", ], [ "from" => "Stockholm", "to" => "New York JFK", ], [ "from" => "Gerona Airport", "to" => "Stockholm", ], [ "from" => "New York JFK", "to" => "Amsterdam", ], [ "from" => "Amsterdam", "to" => "London", ], [ "from" => "Madrid", "to" => "Barcelona", ] ]; $result = []; function doSort($cards, &$result, $start = "Madrid") { foreach ($cards as $key => $card) { if ($card["from"] === $start) { $result[] = $card; doSort($cards, $result, $card["to"]); } } } doSort($cards, $result); print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IFF8A
function name:  (null)
number of ops:  10
compiled vars:  !0 = $cards, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   29     1        ASSIGN                                                   !1, <array>
   39     2        INIT_FCALL                                               'dosort'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_FCALL                                      0          
   40     6        INIT_FCALL                                               'print_r'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function dosort:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 18
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/IFF8A
function name:  doSort
number of ops:  21
compiled vars:  !0 = $cards, !1 = $result, !2 = $start, !3 = $card, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      'Madrid'
   32     3      > FE_RESET_R                                       $5      !0, ->19
          4    > > FE_FETCH_R                                       ~6      $5, !3, ->19
          5    >   ASSIGN                                                   !4, ~6
   33     6        FETCH_DIM_R                                      ~8      !3, 'from'
          7        IS_IDENTICAL                                             !2, ~8
          8      > JMPZ                                                     ~9, ->18
   34     9    >   ASSIGN_DIM                                               !1
         10        OP_DATA                                                  !3
   35    11        INIT_FCALL_BY_NAME                                       'doSort'
         12        SEND_VAR_EX                                              !0
         13        SEND_VAR_EX                                              !1
         14        CHECK_FUNC_ARG                                           
         15        FETCH_DIM_FUNC_ARG                               $11     !3, 'to'
         16        SEND_FUNC_ARG                                            $11
         17        DO_FCALL                                      0          
   32    18    > > JMP                                                      ->4
         19    >   FE_FREE                                                  $5
   38    20      > RETURN                                                   null

End of function dosort

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
135.99 ms | 1001 KiB | 15 Q