3v4l.org

run code in 300+ PHP versions simultaneously
<?php $headers = <<<HEADERS # Hello ## World ### Let's add ## Some headers ### Yay! # Foo ## Bar ## Bar Again HEADERS; $levels = []; echo preg_replace_callback( '~^(#+)\K~m', function($m) use (&$levels) { $hashes = strlen($m[1]); $index = $hashes - 1; $reduction = sizeof($levels) - $hashes; if (!isset($levels[$index])) { $levels[$index] = 1; } else { ++$levels[$index]; } if ($reduction > 0) { $levels = array_slice($levels, 0, -$reduction); } return " " . implode('.', $levels); }, $headers );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SjRfI
function name:  (null)
number of ops:  11
compiled vars:  !0 = $headers, !1 = $levels
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%23+Hello%0A%0A%23%23+World%0A%0A%23%23%23+Let%27s+add%0A%0A%23%23+Some+headers%0A%0A%23%23%23+Yay%21%0A%0A%23+Foo%0A%0A%23%23+Bar%0A%0A%23%23+Bar+Again'
   20     1        ASSIGN                                                   !1, <array>
   21     2        INIT_FCALL                                               'preg_replace_callback'
   22     3        SEND_VAL                                                 '%7E%5E%28%23%2B%29%5CK%7Em'
   23     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FSjRfI%3A23%240'
          5        BIND_LEXICAL                                             ~4, !1
   36     6        SEND_VAL                                                 ~4
   37     7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9        ECHO                                                     $5
   38    10      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FSjRfI%3A23%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 27
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 27
Branch analysis from position: 20
Branch analysis from position: 27
filename:       /in/SjRfI
function name:  {closure}
number of ops:  34
compiled vars:  !0 = $m, !1 = $levels, !2 = $hashes, !3 = $index, !4 = $reduction
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   24     2        FETCH_DIM_R                                      ~5      !0, 1
          3        STRLEN                                           ~6      ~5
          4        ASSIGN                                                   !2, ~6
   25     5        SUB                                              ~8      !2, 1
          6        ASSIGN                                                   !3, ~8
   26     7        COUNT                                            ~10     !1
          8        SUB                                              ~11     ~10, !2
          9        ASSIGN                                                   !4, ~11
   27    10        ISSET_ISEMPTY_DIM_OBJ                         0  ~13     !1, !3
         11        BOOL_NOT                                         ~14     ~13
         12      > JMPZ                                                     ~14, ->16
   28    13    >   ASSIGN_DIM                                               !1, !3
         14        OP_DATA                                                  1
         15      > JMP                                                      ->18
   30    16    >   FETCH_DIM_RW                                     $16     !1, !3
         17        PRE_INC                                                  $16
   32    18    >   IS_SMALLER                                               0, !4
         19      > JMPZ                                                     ~18, ->27
   33    20    >   INIT_FCALL                                               'array_slice'
         21        SEND_VAR                                                 !1
         22        SEND_VAL                                                 0
         23        MUL                                              ~19     !4, -1
         24        SEND_VAL                                                 ~19
         25        DO_ICALL                                         $20     
         26        ASSIGN                                                   !1, $20
   35    27    >   INIT_FCALL                                               'implode'
         28        SEND_VAL                                                 '.'
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                         $22     
         31        CONCAT                                           ~23     '+', $22
         32      > RETURN                                                   ~23
   36    33*     > RETURN                                                   null

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.48 ms | 1400 KiB | 19 Q