3v4l.org

run code in 300+ PHP versions simultaneously
<?php $notifications = [ ['score'=>120,'type'=>5,'post_id'=>1,'subject'=>'a subject','range_day'=>'today'], ['score'=>6,'type'=>4,'post_id'=>2,'subject'=>'a subject','range_day'=>'today'], ['score'=>2,'type'=>4,'post_id'=>3,'subject'=>'a subject','range_day'=>'yesterday'], ]; $template = <<< 'TXT' <li> <p class="subject">{{subject}}<span> | type:{{type}}</span></p> <div class="score">Your score: {{score}}</div> <a href="/{{post_id}}/{{no_space_subject}}"> <span class="date">{{range_day}}</span> </li> TXT; $links = ''; foreach ($notifications as $n){ $n['no_space_subject'] = str_replace(' ','-',$n['subject']); //replace {{VALUE}} with $n[VALUE] in the template. append result //to $links $links .= preg_replace_callback('/{{([^}]+)}}/s', function($m) use ($n){return $n[$m[1]];}, $template ); } echo "<u>$links</u>";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 22
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/KqmWh
function name:  (null)
number of ops:  28
compiled vars:  !0 = $notifications, !1 = $template, !2 = $links, !3 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, '%3Cli%3E%0A+++%3Cp+class%3D%22subject%22%3E%7B%7Bsubject%7D%7D%3Cspan%3E+%7C+type%3A%7B%7Btype%7D%7D%3C%2Fspan%3E%3C%2Fp%3E%0A+++%3Cdiv+class%3D%22score%22%3EYour+score%3A+%7B%7Bscore%7D%7D%3C%2Fdiv%3E%0A+++%3Ca+href%3D%22%2F%7B%7Bpost_id%7D%7D%2F%7B%7Bno_space_subject%7D%7D%22%3E+%0A+++%3Cspan+class%3D%22date%22%3E%7B%7Brange_day%7D%7D%3C%2Fspan%3E%0A%3C%2Fli%3E'
   16     2        ASSIGN                                                   !2, ''
   18     3      > FE_RESET_R                                       $7      !0, ->22
          4    > > FE_FETCH_R                                               $7, !3, ->22
   19     5    >   INIT_FCALL                                               'str_replace'
          6        SEND_VAL                                                 '+'
          7        SEND_VAL                                                 '-'
          8        FETCH_DIM_R                                      ~9      !3, 'subject'
          9        SEND_VAL                                                 ~9
         10        DO_ICALL                                         $10     
         11        ASSIGN_DIM                                               !3, 'no_space_subject'
         12        OP_DATA                                                  $10
   22    13        INIT_FCALL                                               'preg_replace_callback'
         14        SEND_VAL                                                 '%2F%7B%7B%28%5B%5E%7D%5D%2B%29%7D%7D%2Fs'
   23    15        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FKqmWh%3A23%240'
         16        BIND_LEXICAL                                             ~11, !3
         17        SEND_VAL                                                 ~11
   24    18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $12     
         20        ASSIGN_OP                                     8          !2, $12
   18    21      > JMP                                                      ->4
         22    >   FE_FREE                                                  $7
   27    23        ROPE_INIT                                     3  ~15     '%3Cu%3E'
         24        ROPE_ADD                                      1  ~15     ~15, !2
         25        ROPE_END                                      2  ~14     ~15, '%3C%2Fu%3E'
         26        ECHO                                                     ~14
         27      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FKqmWh%3A23%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KqmWh
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $m, !1 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        FETCH_DIM_R                                      ~2      !0, 1
          3        FETCH_DIM_R                                      ~3      !1, ~2
          4      > RETURN                                                   ~3
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FKqmWh%3A23%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.29 ms | 1400 KiB | 17 Q