3v4l.org

run code in 300+ PHP versions simultaneously
<?php const URLS = [ "http://site.com/", "http://site.com/save", "http://site.com/save/results", "http://site.com/save/results/path", "http://site.com/path/save/results", "http://site.com/save/path", "http://site.com/path/results", "http://site.com/Crawler4", "http://site.com/Crawler", ]; $siteStructure = []; foreach (URLS as $url) { // Parse the URL into components ['scheme' => $scheme, 'host' => $host, 'path' => $path] = parse_url($url); // build the slug for the top-level element $realm = $scheme . '://' . $host; // create the top levekl element and get a reference to it $siteStructure[$realm] = $siteStructure[$realm] ?? []; $current = &$siteStructure[$realm]; // parse the path into parts $pathEls = preg_split('/[^a-zA-Z0-9]+/', $path, 0, PREG_SPLIT_NO_EMPTY); foreach ($pathEls as $el) { // for each part, make sure the child array exists and overwrite the reference to the child $current[$el] = $current[$el] ?? []; $current = &$current[$el]; } // delete the reference at the end of the loop to prevent accidents unset($current); } var_dump($siteStructure);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 45
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 45
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 42
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 42
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 42
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
filename:       /in/MFcFR
function name:  (null)
number of ops:  50
compiled vars:  !0 = $siteStructure, !1 = $url, !2 = $scheme, !3 = $host, !4 = $path, !5 = $realm, !6 = $current, !7 = $pathEls, !8 = $el
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                            'URLS', <array>
   15     1        ASSIGN                                                   !0, <array>
   17     2        FETCH_CONSTANT                                   ~10     'URLS'
          3      > FE_RESET_R                                       $11     ~10, ->45
          4    > > FE_FETCH_R                                               $11, !1, ->45
   20     5    >   INIT_FCALL                                               'parse_url'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $12     
          8        FETCH_LIST_R                                     $13     $12, 'scheme'
          9        ASSIGN                                                   !2, $13
         10        FETCH_LIST_R                                     $15     $12, 'host'
         11        ASSIGN                                                   !3, $15
         12        FETCH_LIST_R                                     $17     $12, 'path'
         13        ASSIGN                                                   !4, $17
         14        FREE                                                     $12
   23    15        CONCAT                                           ~19     !2, '%3A%2F%2F'
         16        CONCAT                                           ~20     ~19, !3
         17        ASSIGN                                                   !5, ~20
   26    18        FETCH_DIM_IS                                     ~23     !0, !5
         19        COALESCE                                         ~24     ~23
         20        QM_ASSIGN                                        ~24     <array>
         21        ASSIGN_DIM                                               !0, !5
         22        OP_DATA                                                  ~24
   27    23        FETCH_DIM_W                                      $25     !0, !5
         24        ASSIGN_REF                                               !6, $25
   30    25        INIT_FCALL                                               'preg_split'
         26        SEND_VAL                                                 '%2F%5B%5Ea-zA-Z0-9%5D%2B%2F'
         27        SEND_VAR                                                 !4
         28        SEND_VAL                                                 0
         29        SEND_VAL                                                 1
         30        DO_ICALL                                         $27     
         31        ASSIGN                                                   !7, $27
   32    32      > FE_RESET_R                                       $29     !7, ->42
         33    > > FE_FETCH_R                                               $29, !8, ->42
   35    34    >   FETCH_DIM_IS                                     ~31     !6, !8
         35        COALESCE                                         ~32     ~31
         36        QM_ASSIGN                                        ~32     <array>
         37        ASSIGN_DIM                                               !6, !8
         38        OP_DATA                                                  ~32
   36    39        FETCH_DIM_W                                      $33     !6, !8
         40        ASSIGN_REF                                               !6, $33
   32    41      > JMP                                                      ->33
         42    >   FE_FREE                                                  $29
   40    43        UNSET_CV                                                 !6
   17    44      > JMP                                                      ->4
         45    >   FE_FREE                                                  $11
   43    46        INIT_FCALL                                               'var_dump'
         47        SEND_VAR                                                 !0
         48        DO_ICALL                                                 
         49      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.02 ms | 1400 KiB | 19 Q