3v4l.org

run code in 300+ PHP versions simultaneously
<?php $comment = " some text {Varinat #3 smth} {Varinat #4 smth else} {Varinat #1 smth else 1} some another text {Varinat #2 smth else 2} {Varinat #5 smth else 5} "; $lines = explode("\n",$comment); $processed = array_map(function($line) { if( preg_match('(^\{Varinat #(\d+))', $line, $match)) { return [$line,$match[1]]; } return [$line,null]; }, $lines); $variant = array_filter($processed,function($data) {return $data[1];}); usort($variant,function($a,$b) {return $a[1] - $b[1];}); $sorted = array_map(function($data) use (&$variant) { if( $data[1]) return array_shift($variant)[0]; else return $data[0]; },$processed); $result = implode("\n",$sorted); echo $result;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nVBYl
function name:  (null)
number of ops:  37
compiled vars:  !0 = $comment, !1 = $lines, !2 = $processed, !3 = $variant, !4 = $sorted, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%0Asome+text%0A%0A%7BVarinat+%233+smth%7D%0A%7BVarinat+%234+smth+else%7D%0A%7BVarinat+%231+smth+else+1%7D%0Asome+another+text%0A%7BVarinat+%232+smth+else+2%7D%0A%7BVarinat+%235+smth+else+5%7D%0A'
   13     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%0A'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !1, $7
   14     6        INIT_FCALL                                               'array_map'
          7        DECLARE_LAMBDA_FUNCTION                          ~9      [0]
   19     8        SEND_VAL                                                 ~9
          9        SEND_VAR                                                 !1
   14    10        DO_ICALL                                         $10     
         11        ASSIGN                                                   !2, $10
   20    12        INIT_FCALL                                               'array_filter'
         13        SEND_VAR                                                 !2
         14        DECLARE_LAMBDA_FUNCTION                          ~12     [1]
         15        SEND_VAL                                                 ~12
         16        DO_ICALL                                         $13     
         17        ASSIGN                                                   !3, $13
   21    18        INIT_FCALL                                               'usort'
         19        SEND_REF                                                 !3
         20        DECLARE_LAMBDA_FUNCTION                          ~15     [2]
         21        SEND_VAL                                                 ~15
         22        DO_ICALL                                                 
   22    23        INIT_FCALL                                               'array_map'
         24        DECLARE_LAMBDA_FUNCTION                          ~17     [3]
         25        BIND_LEXICAL                                             ~17, !3
   25    26        SEND_VAL                                                 ~17
         27        SEND_VAR                                                 !2
   22    28        DO_ICALL                                         $18     
         29        ASSIGN                                                   !4, $18
   26    30        INIT_FCALL                                               'implode'
         31        SEND_VAL                                                 '%0A'
         32        SEND_VAR                                                 !4
         33        DO_ICALL                                         $20     
         34        ASSIGN                                                   !5, $20
   28    35        ECHO                                                     !5
   29    36      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nVBYl
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $line, !1 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%28%5E%5C%7BVarinat+%23%28%5Cd%2B%29%29'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->11
   16     7    >   INIT_ARRAY                                       ~3      !0
          8        FETCH_DIM_R                                      ~4      !1, 1
          9        ADD_ARRAY_ELEMENT                                ~3      ~4
         10      > RETURN                                                   ~3
   18    11    >   INIT_ARRAY                                       ~5      !0
         12        ADD_ARRAY_ELEMENT                                ~5      null
         13      > RETURN                                                   ~5
   19    14*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nVBYl
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        FETCH_DIM_R                                      ~1      !0, 1
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nVBYl
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        FETCH_DIM_R                                      ~2      !0, 1
          3        FETCH_DIM_R                                      ~3      !1, 1
          4        SUB                                              ~4      ~2, ~3
          5      > RETURN                                                   ~4
          6*     > RETURN                                                   null

End of Dynamic Function 2

Dynamic Function 3
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nVBYl
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $data, !1 = $variant
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   23     2        FETCH_DIM_R                                      ~2      !0, 1
          3      > JMPZ                                                     ~2, ->10
          4    >   INIT_FCALL                                               'array_shift'
          5        SEND_REF                                                 !1
          6        DO_ICALL                                         $3      
          7        FETCH_DIM_R                                      ~4      $3, 0
          8      > RETURN                                                   ~4
          9*       JMP                                                      ->12
   24    10    >   FETCH_DIM_R                                      ~5      !0, 0
         11      > RETURN                                                   ~5
   25    12*     > RETURN                                                   null

End of Dynamic Function 3

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.43 ms | 1026 KiB | 20 Q