3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<html> <body> <table> <thead> <tr> <th>Name</th> <th>Date</th> </tr> </thead> <tbody> <tr> <td>Chad</td> <td>10/23/1996</td> </tr> <tr> <td>Rebecca</td> <td>05/03/2001</td> </tbody> </table> </body> </html>'; $dom = new DOMDocument(); $dom->loadHTML($html); $headers = $dom->getElementsByTagName('th'); foreach($headers as $header) { $keys[] = $header->nodeValue; } $rows = $dom->getElementsByTagName('tbody')->item(0)->getElementsByTagName('tr'); $result = []; foreach($rows as $row) { $item = []; foreach($keys as $i => $key) { $cells = $row->getElementsByTagName('td'); $item[$key] = $cells->item($i)->nodeValue; } $result[] = $item; } var_dump($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 50
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 50
Branch analysis from position: 31
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 46
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 46
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 46
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 17
filename:       /in/v4cQY
function name:  (null)
number of ops:  55
compiled vars:  !0 = $html, !1 = $dom, !2 = $headers, !3 = $header, !4 = $keys, !5 = $rows, !6 = $result, !7 = $row, !8 = $item, !9 = $key, !10 = $i, !11 = $cells
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Chtml%3E%0A%3Cbody%3E%0A++++%3Ctable%3E%0A++++++++%3Cthead%3E%0A++++++++++++%3Ctr%3E%0A++++++++++++++++%3Cth%3EName%3C%2Fth%3E%0A++++++++++++++++%3Cth%3EDate%3C%2Fth%3E%0A++++++++++++%3C%2Ftr%3E%0A++++++++%3C%2Fthead%3E%0A++++++++%3Ctbody%3E%0A++++++++++++%3Ctr%3E%0A++++++++++++++++%3Ctd%3EChad%3C%2Ftd%3E%0A++++++++++++++++%3Ctd%3E10%2F23%2F1996%3C%2Ftd%3E%0A++++++++++++%3C%2Ftr%3E%0A++++++++++++%3Ctr%3E%0A++++++++++++++++%3Ctd%3ERebecca%3C%2Ftd%3E%0A++++++++++++++++%3Ctd%3E05%2F03%2F2001%3C%2Ftd%3E%0A++++++++%3C%2Ftbody%3E%0A++++%3C%2Ftable%3E%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   25     1        NEW                                              $13     'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $13
   26     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   28     7        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
          8        SEND_VAL_EX                                              'th'
          9        DO_FCALL                                      0  $17     
         10        ASSIGN                                                   !2, $17
   30    11      > FE_RESET_R                                       $19     !2, ->17
         12    > > FE_FETCH_R                                               $19, !3, ->17
   31    13    >   FETCH_OBJ_R                                      ~21     !3, 'nodeValue'
         14        ASSIGN_DIM                                               !4
         15        OP_DATA                                                  ~21
   30    16      > JMP                                                      ->12
         17    >   FE_FREE                                                  $19
   34    18        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         19        SEND_VAL_EX                                              'tbody'
         20        DO_FCALL                                      0  $22     
         21        INIT_METHOD_CALL                                         $22, 'item'
         22        SEND_VAL_EX                                              0
         23        DO_FCALL                                      0  $23     
         24        INIT_METHOD_CALL                                         $23, 'getElementsByTagName'
         25        SEND_VAL_EX                                              'tr'
         26        DO_FCALL                                      0  $24     
         27        ASSIGN                                                   !5, $24
   35    28        ASSIGN                                                   !6, <array>
   37    29      > FE_RESET_R                                       $27     !5, ->50
         30    > > FE_FETCH_R                                               $27, !7, ->50
   38    31    >   ASSIGN                                                   !8, <array>
   39    32      > FE_RESET_R                                       $29     !4, ->46
         33    > > FE_FETCH_R                                       ~30     $29, !9, ->46
         34    >   ASSIGN                                                   !10, ~30
   40    35        INIT_METHOD_CALL                                         !7, 'getElementsByTagName'
         36        SEND_VAL_EX                                              'td'
         37        DO_FCALL                                      0  $32     
         38        ASSIGN                                                   !11, $32
   41    39        INIT_METHOD_CALL                                         !11, 'item'
         40        SEND_VAR_EX                                              !10
         41        DO_FCALL                                      0  $35     
         42        FETCH_OBJ_R                                      ~36     $35, 'nodeValue'
         43        ASSIGN_DIM                                               !8, !9
         44        OP_DATA                                                  ~36
   39    45      > JMP                                                      ->33
         46    >   FE_FREE                                                  $29
   43    47        ASSIGN_DIM                                               !6
         48        OP_DATA                                                  !8
   37    49      > JMP                                                      ->30
         50    >   FE_FREE                                                  $27
   46    51        INIT_FCALL                                               'var_dump'
         52        SEND_VAR                                                 !6
         53        DO_ICALL                                                 
         54      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.25 ms | 1408 KiB | 16 Q