3v4l.org

run code in 300+ PHP versions simultaneously
<?php $handle = fopen('music_asdlist.txt', 'r'); $blocks = array(); $currentBlock = array(); while (!feof($handle)) { $line = fgets($handle); if (trim($line) == '') { if ($currentBlock) { $blocks[] = $currentBlock; $currentBlock = array(); } } else { $currentBlock[] = $line; } } fclose($handle); if ($currentBlock) { $blocks[] = $currentBlock; } function findTerm($term, $haystack) { $count = 0; foreach($haystack as $album) { if(in_array($term, $album)) { return $count; } } return false; } if(empty($blocks)) { echo "File import failed"; } else { $searchTerm = "strategy"; $album = findTerm($searhTerm, $blocks); if(isset($album)) { echo "Found term: <b>$searchTerm</b><br>"; echo "In album: ".$blocks[$album][2]; } } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 8
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 55
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
Branch analysis from position: 35
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 21
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 8
Branch analysis from position: 29
Branch analysis from position: 8
filename:       /in/3h3uU
function name:  (null)
number of ops:  56
compiled vars:  !0 = $handle, !1 = $blocks, !2 = $currentBlock, !3 = $line, !4 = $searchTerm, !5 = $album, !6 = $searhTerm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'fopen'
          1        SEND_VAL                                                 'music_asdlist.txt'
          2        SEND_VAL                                                 'r'
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !0, $7
    3     5        ASSIGN                                                   !1, <array>
    4     6        ASSIGN                                                   !2, <array>
    5     7      > JMP                                                      ->24
    6     8    >   INIT_FCALL                                               'fgets'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !3, $11
    7    12        INIT_FCALL                                               'trim'
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $13     
         15        IS_EQUAL                                                 $13, ''
         16      > JMPZ                                                     ~14, ->22
    8    17    > > JMPZ                                                     !2, ->21
    9    18    >   ASSIGN_DIM                                               !1
         19        OP_DATA                                                  !2
   10    20        ASSIGN                                                   !2, <array>
         21    > > JMP                                                      ->24
   13    22    >   ASSIGN_DIM                                               !2
         23        OP_DATA                                                  !3
    5    24    >   INIT_FCALL                                               'feof'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $18     
         27        BOOL_NOT                                         ~19     $18
         28      > JMPNZ                                                    ~19, ->8
   16    29    >   INIT_FCALL                                               'fclose'
         30        SEND_VAR                                                 !0
         31        DO_ICALL                                                 
   18    32      > JMPZ                                                     !2, ->35
   19    33    >   ASSIGN_DIM                                               !1
         34        OP_DATA                                                  !2
   32    35    >   ISSET_ISEMPTY_CV                                         !1
         36      > JMPZ                                                     ~22, ->39
   33    37    >   ECHO                                                     'File+import+failed'
         38      > JMP                                                      ->55
   36    39    >   ASSIGN                                                   !4, 'strategy'
   37    40        INIT_FCALL                                               'findterm'
         41        SEND_VAR                                                 !6
         42        SEND_VAR                                                 !1
         43        DO_FCALL                                      0  $24     
         44        ASSIGN                                                   !5, $24
   39    45        ISSET_ISEMPTY_CV                                         !5
         46      > JMPZ                                                     ~26, ->55
   40    47    >   ROPE_INIT                                     3  ~28     'Found+term%3A+%3Cb%3E'
         48        ROPE_ADD                                      1  ~28     ~28, !4
         49        ROPE_END                                      2  ~27     ~28, '%3C%2Fb%3E%3Cbr%3E'
         50        ECHO                                                     ~27
   41    51        FETCH_DIM_R                                      ~30     !1, !5
         52        FETCH_DIM_R                                      ~31     ~30, 2
         53        CONCAT                                           ~32     'In+album%3A+', ~31
         54        ECHO                                                     ~32
   44    55    > > RETURN                                                   1

Function findterm:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/3h3uU
function name:  findTerm
number of ops:  16
compiled vars:  !0 = $term, !1 = $haystack, !2 = $count, !3 = $album
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2        ASSIGN                                                   !2, 0
   24     3      > FE_RESET_R                                       $5      !1, ->13
          4    > > FE_FETCH_R                                               $5, !3, ->13
   25     5    >   INIT_FCALL                                               'in_array'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $6      
          9      > JMPZ                                                     $6, ->12
   26    10    >   FE_FREE                                                  $5
         11      > RETURN                                                   !2
   24    12    > > JMP                                                      ->4
         13    >   FE_FREE                                                  $5
   29    14      > RETURN                                                   <false>
   30    15*     > RETURN                                                   null

End of function findterm

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.51 ms | 1407 KiB | 26 Q