3v4l.org

run code in 500+ PHP versions simultaneously
<?php function showCell($cell, $isHeader, $selectedTitle) { echo '<td>'; if ($selectedTitle || $isHeader) { echo htmlspecialchars($cell); } else { echo sprintf('<a href="?title=%1$s">%1$s</a>', htmlspecialchars($cell)); } echo '</td>', PHP_EOL; } function showRow($cellsToShow, $isHeader, $selectedTitle) { if ($isHeader) { echo '<thead>', PHP_EOL; } echo '<tr>', PHP_EOL; foreach ($cellsToShow as $cell) { showCell($cell, $isHeader, $selectedTitle); } echo '</tr>', PHP_EOL; if ($isHeader) { echo '</thead>', PHP_EOL; } } function showTable($handle, $selectedTitle) { $idx = 0; echo '<table>', PHP_EOL; while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) { // If we're on the first row which holds titles, always show. // Also, if the user selected a title, and it matches this row's title, show it. if(0 !== $idx && $selectedTitle && $row[0] !== $selectedTitle){ continue; } // cellsToShow is always an array. If we're showing based on a selection, it is everything. // Otherwise, it will be an array of just the first cell. This last seems weird, but it // allows the showRow method to not concern itself with higher level logic. $cellsToShow = $selectedTitle ? $row : [$row[0]]; showRow($cellsToShow, $idx++ === 0, $selectedTitle); } echo '</table>', PHP_EOL; } // Mock a CSV file in memory for demo purposes $handle = fopen('php://memory', 'rb+'); fwrite($handle, "Title,Author,Year\nBook 1,Alice,2020\nBook 2,Bob,2019\nBook 3,Charlie,1980"); rewind($handle); // Grab the title from the query string, default to null if not found $selectedTitle = $_GET['title'] ?? null; showTable($handle, $selectedTitle); fclose($handle);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/33ose
function name:  (null)
number of ops:  25
compiled vars:  !0 = $handle, !1 = $selectedTitle
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   51     0  E >   INIT_FCALL                                                   'fopen'
          1        SEND_VAL                                                     'php%3A%2F%2Fmemory'
          2        SEND_VAL                                                     'rb%2B'
          3        DO_ICALL                                             $2      
          4        ASSIGN                                                       !0, $2
   52     5        INIT_FCALL                                                   'fwrite'
          6        SEND_VAR                                                     !0
          7        SEND_VAL                                                     'Title%2CAuthor%2CYear%0ABook+1%2CAlice%2C2020%0ABook+2%2CBob%2C2019%0ABook+3%2CCharlie%2C1980'
          8        DO_ICALL                                                     
   53     9        INIT_FCALL                                                   'rewind'
         10        SEND_VAR                                                     !0
         11        DO_ICALL                                                     
   56    12        FETCH_IS                                             ~6      '_GET'
         13        FETCH_DIM_IS                                         ~7      ~6, 'title'
         14        COALESCE                                             ~8      ~7
         15        QM_ASSIGN                                            ~8      null
         16        ASSIGN                                                       !1, ~8
   58    17        INIT_FCALL                                                   'showtable'
         18        SEND_VAR                                                     !0
         19        SEND_VAR                                                     !1
         20        DO_FCALL                                          0          
   60    21        INIT_FCALL                                                   'fclose'
         22        SEND_VAR                                                     !0
         23        DO_ICALL                                                     
         24      > RETURN                                                       1

Function showcell:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/33ose
function name:  showCell
number of ops:  23
compiled vars:  !0 = $cell, !1 = $isHeader, !2 = $selectedTitle
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
    5     3        ECHO                                                         '%3Ctd%3E'
    6     4      > JMPNZ_EX                                             ~3      !2, ->6
          5    >   BOOL                                                 ~3      !1
          6    > > JMPZ                                                         ~3, ->12
    7     7    >   INIT_FCALL                                                   'htmlspecialchars'
          8        SEND_VAR                                                     !0
          9        DO_ICALL                                             $4      
         10        ECHO                                                         $4
    6    11      > JMP                                                          ->20
    9    12    >   INIT_FCALL                                                   'sprintf'
         13        SEND_VAL                                                     '%3Ca+href%3D%22%3Ftitle%3D%251%24s%22%3E%251%24s%3C%2Fa%3E'
         14        INIT_FCALL                                                   'htmlspecialchars'
         15        SEND_VAR                                                     !0
         16        DO_ICALL                                             $5      
         17        SEND_VAR                                                     $5
         18        DO_ICALL                                             $6      
         19        ECHO                                                         $6
   11    20    >   ECHO                                                         '%3C%2Ftd%3E'
         21        ECHO                                                         '%0A'
   12    22      > RETURN                                                       null

End of function showcell

Function showrow:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 16
Branch analysis from position: 6
filename:       /in/33ose
function name:  showRow
number of ops:  23
compiled vars:  !0 = $cellsToShow, !1 = $isHeader, !2 = $selectedTitle, !3 = $cell
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   16     3      > JMPZ                                                         !1, ->6
   17     4    >   ECHO                                                         '%3Cthead%3E'
          5        ECHO                                                         '%0A'
   20     6    >   ECHO                                                         '%3Ctr%3E'
          7        ECHO                                                         '%0A'
   21     8      > FE_RESET_R                                           $4      !0, ->16
          9    > > FE_FETCH_R                                                   $4, !3, ->16
   22    10    >   INIT_FCALL                                                   'showcell'
         11        SEND_VAR                                                     !3
         12        SEND_VAR                                                     !1
         13        SEND_VAR                                                     !2
         14        DO_FCALL                                          0          
   21    15      > JMP                                                          ->9
         16    >   FE_FREE                                                      $4
   24    17        ECHO                                                         '%3C%2Ftr%3E'
         18        ECHO                                                         '%0A'
   26    19      > JMPZ                                                         !1, ->22
   27    20    >   ECHO                                                         '%3C%2Fthead%3E'
         21        ECHO                                                         '%0A'
   29    22    > > RETURN                                                       null

End of function showrow

Function showtable:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 6
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 6
Branch analysis from position: 37
Branch analysis from position: 6
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 6
Branch analysis from position: 37
Branch analysis from position: 6
Branch analysis from position: 13
Branch analysis from position: 9
filename:       /in/33ose
function name:  showTable
number of ops:  40
compiled vars:  !0 = $handle, !1 = $selectedTitle, !2 = $idx, !3 = $row, !4 = $cellsToShow
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   31     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   33     2        ASSIGN                                                       !2, 0
   34     3        ECHO                                                         '%3Ctable%3E'
          4        ECHO                                                         '%0A'
   35     5      > JMP                                                          ->29
   38     6    >   IS_NOT_IDENTICAL                                     ~6      !2, 0
          7      > JMPZ_EX                                              ~6      ~6, ->9
          8    >   BOOL                                                 ~6      !1
          9    > > JMPZ_EX                                              ~6      ~6, ->13
         10    >   FETCH_DIM_R                                          ~7      !3, 0
         11        IS_NOT_IDENTICAL                                     ~8      !1, ~7
         12        BOOL                                                 ~6      ~8
         13    > > JMPZ                                                         ~6, ->15
   39    14    > > JMP                                                          ->29
   44    15    > > JMPZ                                                         !1, ->18
         16    >   QM_ASSIGN                                            ~9      !3
         17      > JMP                                                          ->21
         18    >   FETCH_DIM_R                                          ~10     !3, 0
         19        INIT_ARRAY                                           ~11     ~10
         20        QM_ASSIGN                                            ~9      ~11
         21    >   ASSIGN                                                       !4, ~9
   45    22        INIT_FCALL                                                   'showrow'
         23        SEND_VAR                                                     !4
         24        POST_INC                                             ~13     !2
         25        IS_IDENTICAL                                         ~14     ~13, 0
         26        SEND_VAL                                                     ~14
         27        SEND_VAR                                                     !1
         28        DO_FCALL                                          0          
   35    29    >   INIT_FCALL                                                   'fgetcsv'
         30        SEND_VAR                                                     !0
         31        SEND_VAL                                                     1000
         32        SEND_VAL                                                     '%2C'
         33        DO_ICALL                                             $16     
         34        ASSIGN                                               ~17     !3, $16
         35        TYPE_CHECK                                      1018          ~17
         36      > JMPNZ                                                        ~18, ->6
   47    37    >   ECHO                                                         '%3C%2Ftable%3E'
         38        ECHO                                                         '%0A'
   48    39      > RETURN                                                       null

End of function showtable

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
164.16 ms | 1818 KiB | 23 Q