3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "foo (20/50) bar () baz (11/30)"; $pattern = '~\G(?<title>\S+)\h+\((?:(?<number>\d+)/\d+)?\)(?:\s|$)~'; preg_match_all($pattern, $str, $matches, PREG_SET_ORDER, 0); $matches = array_reduce($matches, function($carry, $item) { $carry[] = [ "title" => $item["title"], "number" => array_key_exists("number", $item) ? $item["number"] : 0 ]; return $carry; }); print_r($matches);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/viRCn
function name:  (null)
number of ops:  19
compiled vars:  !0 = $str, !1 = $pattern, !2 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'foo+%2820%2F50%29+bar+%28%29+baz+%2811%2F30%29'
    4     1        ASSIGN                                                   !1, '%7E%5CG%28%3F%3Ctitle%3E%5CS%2B%29%5Ch%2B%5C%28%28%3F%3A%28%3F%3Cnumber%3E%5Cd%2B%29%2F%5Cd%2B%29%3F%5C%29%28%3F%3A%5Cs%7C%24%29%7E'
    5     2        INIT_FCALL                                               'preg_match_all'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !2
          6        SEND_VAL                                                 2
          7        SEND_VAL                                                 0
          8        DO_ICALL                                                 
    6     9        INIT_FCALL                                               'array_reduce'
         10        SEND_VAR                                                 !2
         11        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
   13    12        SEND_VAL                                                 ~6
    6    13        DO_ICALL                                         $7      
         14        ASSIGN                                                   !2, $7
   16    15        INIT_FCALL                                               'print_r'
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                                 
         18      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/viRCn
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $carry, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        FETCH_DIM_R                                      ~3      !1, 'title'
          3        INIT_ARRAY                                       ~4      ~3, 'title'
    9     4        ARRAY_KEY_EXISTS                                         'number', !1
          5      > JMPZ                                                     ~5, ->9
          6    >   FETCH_DIM_R                                      ~6      !1, 'number'
          7        QM_ASSIGN                                        ~7      ~6
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~7      0
         10    >   ADD_ARRAY_ELEMENT                                ~4      ~7, 'number'
    7    11        ASSIGN_DIM                                               !0
    9    12        OP_DATA                                                  ~4
   12    13      > RETURN                                                   !0
   13    14*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.06 ms | 1013 KiB | 16 Q