3v4l.org

run code in 300+ PHP versions simultaneously
<?php function cross_product($array, $value) { $output = array(); foreach ($array as $arr) { foreach ($value as $val) { $output[] = array_merge($arr, array($val)); } } return $output; } $input = "A1 / B2 - C3 + D4 / E5 / E6 C3 + A5"; $parts = preg_split('/(?<=[A-Za-z0-9])\s+(?=[A-IK-Za-ik-z])|\s+([+-])\s+/', $input, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($parts as &$part) { $part = preg_split('#\s+/\s+#', $part); } $init = array_map(function ($v) { return array($v); }, array_shift($parts)); $outputs = array_reduce($parts, 'cross_product', $init); foreach ($outputs as $output) { echo implode(' ', $output) . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
2 jumps found. (Code = 126) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 41
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 41
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
Branch analysis from position: 16
filename:       /in/9ICTq
function name:  (null)
number of ops:  43
compiled vars:  !0 = $input, !1 = $parts, !2 = $part, !3 = $init, !4 = $outputs, !5 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, 'A1+%2F+B2+-+C3+%2B+D4+%2F+E5+%2F+E6+C3+%2B+A5'
   13     1        INIT_FCALL                                               'preg_split'
          2        SEND_VAL                                                 '%2F%28%3F%3C%3D%5BA-Za-z0-9%5D%29%5Cs%2B%28%3F%3D%5BA-IK-Za-ik-z%5D%29%7C%5Cs%2B%28%5B%2B-%5D%29%5Cs%2B%2F'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 -1
          5        SEND_VAL                                                 2
          6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !1, $7
   15     8      > FE_RESET_RW                                      $9      !1, ->16
          9    > > FE_FETCH_RW                                              $9, !2, ->16
   16    10    >   INIT_FCALL                                               'preg_split'
         11        SEND_VAL                                                 '%23%5Cs%2B%2F%5Cs%2B%23'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $10     
         14        ASSIGN                                                   !2, $10
   15    15      > JMP                                                      ->9
         16    >   FE_FREE                                                  $9
   19    17        INIT_FCALL                                               'array_map'
         18        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F9ICTq%3A19%240'
         19        SEND_VAL                                                 ~12
         20        INIT_FCALL                                               'array_shift'
         21        SEND_REF                                                 !1
         22        DO_ICALL                                         $13     
         23        SEND_VAR                                                 $13
         24        DO_ICALL                                         $14     
         25        ASSIGN                                                   !3, $14
   21    26        INIT_FCALL                                               'array_reduce'
         27        SEND_VAR                                                 !1
         28        SEND_VAL                                                 'cross_product'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $16     
         31        ASSIGN                                                   !4, $16
   23    32      > FE_RESET_R                                       $18     !4, ->41
         33    > > FE_FETCH_R                                               $18, !5, ->41
   24    34    >   INIT_FCALL                                               'implode'
         35        SEND_VAL                                                 '+'
         36        SEND_VAR                                                 !5
         37        DO_ICALL                                         $19     
         38        CONCAT                                           ~20     $19, '%0A'
         39        ECHO                                                     ~20
   23    40      > JMP                                                      ->33
         41    >   FE_FREE                                                  $18
   25    42      > RETURN                                                   1

Function cross_product:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 17
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 15
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/9ICTq
function name:  cross_product
number of ops:  20
compiled vars:  !0 = $array, !1 = $value, !2 = $output, !3 = $arr, !4 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        ASSIGN                                                   !2, <array>
    4     3      > FE_RESET_R                                       $6      !0, ->17
          4    > > FE_FETCH_R                                               $6, !3, ->17
    5     5    > > FE_RESET_R                                       $7      !1, ->15
          6    > > FE_FETCH_R                                               $7, !4, ->15
    6     7    >   INIT_FCALL                                               'array_merge'
          8        SEND_VAR                                                 !3
          9        INIT_ARRAY                                       ~9      !4
         10        SEND_VAL                                                 ~9
         11        DO_ICALL                                         $10     
         12        ASSIGN_DIM                                               !2
         13        OP_DATA                                                  $10
    5    14      > JMP                                                      ->6
         15    >   FE_FREE                                                  $7
    4    16      > JMP                                                      ->4
         17    >   FE_FREE                                                  $6
    9    18      > RETURN                                                   !2
   10    19*     > RETURN                                                   null

End of function cross_product

Function %00%7Bclosure%7D%2Fin%2F9ICTq%3A19%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9ICTq
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        INIT_ARRAY                                       ~1      !0
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F9ICTq%3A19%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.3 ms | 1409 KiB | 25 Q