3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input= "<p>text text text</p> <p>text text text</p> <p>text text text</p> <p>text text text</p> <p>text text text</p> <p>text text text</p>"; $arr =explode(PHP_EOL, $input); $adsbeforeparagraph = array(0,2,4); // subtracted 1 to suit normal array numbering $ad = 'ADS CODE'; Foreach($arr as $key => $line){ If(in_array($key, $adsbeforeparagraph)){ // is this a line that should have Ads? Echo $ad . $line . "\n"; }else{ Echo $line . "\n"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 23
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 23
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/8DVua
function name:  (null)
number of ops:  25
compiled vars:  !0 = $input, !1 = $arr, !2 = $adsbeforeparagraph, !3 = $ad, !4 = $line, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cp%3Etext+text+text%3C%2Fp%3E%0A%3Cp%3Etext+text+text%3C%2Fp%3E%0A%3Cp%3Etext+text+text%3C%2Fp%3E%0A%3Cp%3Etext+text+text%3C%2Fp%3E%0A%3Cp%3Etext+text+text%3C%2Fp%3E%0A%3Cp%3Etext+text+text%3C%2Fp%3E'
   10     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%0A'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !1, $7
   12     6        ASSIGN                                                   !2, <array>
   13     7        ASSIGN                                                   !3, 'ADS+CODE'
   15     8      > FE_RESET_R                                       $11     !1, ->23
          9    > > FE_FETCH_R                                       ~12     $11, !4, ->23
         10    >   ASSIGN                                                   !5, ~12
   16    11        INIT_FCALL                                               'in_array'
         12        SEND_VAR                                                 !5
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $14     
         15      > JMPZ                                                     $14, ->20
   17    16    >   CONCAT                                           ~15     !3, !4
         17        CONCAT                                           ~16     ~15, '%0A'
         18        ECHO                                                     ~16
   16    19      > JMP                                                      ->22
   19    20    >   CONCAT                                           ~17     !4, '%0A'
         21        ECHO                                                     ~17
   15    22    > > JMP                                                      ->9
         23    >   FE_FREE                                                  $11
   21    24      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.04 ms | 1000 KiB | 15 Q