3v4l.org

run code in 300+ PHP versions simultaneously
<?php $handle = fopen('music_list.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; } $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 = 43, Position 2 = 51
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
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/lmFlX
function name:  (null)
number of ops:  52
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_list.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
   33    35    >   ASSIGN                                                   !4, 'strategy'
   34    36        INIT_FCALL                                               'findterm'
         37        SEND_VAR                                                 !6
         38        SEND_VAR                                                 !1
         39        DO_FCALL                                      0  $23     
         40        ASSIGN                                                   !5, $23
   36    41        ISSET_ISEMPTY_CV                                         !5
         42      > JMPZ                                                     ~25, ->51
   37    43    >   ROPE_INIT                                     3  ~27     'Found+term%3A+%3Cb%3E'
         44        ROPE_ADD                                      1  ~27     ~27, !4
         45        ROPE_END                                      2  ~26     ~27, '%3C%2Fb%3E%3Cbr%3E'
         46        ECHO                                                     ~26
   38    47        FETCH_DIM_R                                      ~29     !1, !5
         48        FETCH_DIM_R                                      ~30     ~29, 2
         49        CONCAT                                           ~31     'In+album%3A+', ~30
         50        ECHO                                                     ~31
   41    51    > > 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/lmFlX
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:
158.54 ms | 1394 KiB | 26 Q