3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function stringMultiplicate($first, $second) { // Create array include result of 1 number in $second string * first $result = []; $strFirst = (string)$first; $strSecond = (string)$second; $maxLength = 0; for ($i = strlen($strSecond) - 1; $i >= 0; $i--) { $index = $i; $number = (int)$strSecond[$i]; $result[$index] = ''; $k = strlen($strSecond) - 1 - $i; $div = 0; for ($j = (strlen($strFirst) - 1); $j >= 0; $j--) { while ($k != 0) { $result[$index] .= '0'; $k--; } $next = ($number * $strFirst[$j] + $div); if (strlen($next) > 1 && $j != 0) { $result[$index] .= ((string)$next)[strlen($next) - 1]; $div = ((string)$next)[0]; } else { $result[$index] .= $number * $strFirst[$j] + $div; $div = 0; } } if (strlen($result[$index]) > $maxLength) { $maxLength = $result[$index]; } $result[$index] = strrev($result[$index]); } $multi = []; for ($j = 0; $j < $maxLength; $j++) { $sum = 0; for ($i = 0; $i < count($result); $i++) { var_dump($result[$i]); if (!isset($result[$i][$j])) { $result[$i][$j] = 0; } $sum += (int)$result[$i][$j]; } $multi[$j] = $sum; } return $multi; } var_dump(stringMultiplicate(12345, 123)); var_dump(12345*123);
based on c1drQ
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eSJHI
function name:  (null)
number of ops:  12
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
  56     1        INIT_FCALL                                               'var_dump'
         2        INIT_FCALL                                               'stringmultiplicate'
         3        SEND_VAL                                                 12345
         4        SEND_VAL                                                 123
         5        DO_FCALL                                      0  $0      
         6        SEND_VAR                                                 $0
         7        DO_ICALL                                                 
  57     8        INIT_FCALL                                               'var_dump'
         9        SEND_VAL                                                 1518435
        10        DO_ICALL                                                 
        11      > RETURN                                                   1

Function stringmultiplicate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 12
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 110
Branch analysis from position: 110
2 jumps found. (Code = 44) Position 1 = 112, Position 2 = 83
Branch analysis from position: 112
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 83
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
2 jumps found. (Code = 44) Position 1 = 106, Position 2 = 86
Branch analysis from position: 106
2 jumps found. (Code = 44) Position 1 = 112, Position 2 = 83
Branch analysis from position: 112
Branch analysis from position: 83
Branch analysis from position: 86
2 jumps found. (Code = 43) Position 1 = 94, Position 2 = 97
Branch analysis from position: 94
2 jumps found. (Code = 44) Position 1 = 106, Position 2 = 86
Branch analysis from position: 106
Branch analysis from position: 86
Branch analysis from position: 97
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 27
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 70
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 12
Branch analysis from position: 80
Branch analysis from position: 12
Branch analysis from position: 70
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 28
Branch analysis from position: 34
2 jumps found. (Code = 46) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 54
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 27
Branch analysis from position: 64
Branch analysis from position: 27
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 27
Branch analysis from position: 64
Branch analysis from position: 27
Branch analysis from position: 43
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 28
Branch analysis from position: 34
Branch analysis from position: 28
filename:       /in/eSJHI
function name:  stringMultiplicate
number of ops:  114
compiled vars:  !0 = $first, !1 = $second, !2 = $result, !3 = $strFirst, !4 = $strSecond, !5 = $maxLength, !6 = $i, !7 = $index, !8 = $number, !9 = $k, !10 = $div, !11 = $j, !12 = $next, !13 = $multi, !14 = $sum
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   RECV                                             !0      
         1        RECV                                             !1      
   5     2        ASSIGN                                                   !2, <array>
   6     3        CAST                                          6  ~16     !0
         4        ASSIGN                                                   !3, ~16
   7     5        CAST                                          6  ~18     !1
         6        ASSIGN                                                   !4, ~18
   9     7        ASSIGN                                                   !5, 0
  10     8        STRLEN                                           ~21     !4
         9        SUB                                              ~22     ~21, 1
        10        ASSIGN                                                   !6, ~22
        11      > JMP                                                      ->78
  11    12    >   ASSIGN                                                   !7, !6
  12    13        FETCH_DIM_R                                      $25     !4, !6
        14        CAST                                          4  ~26     $25
        15        ASSIGN                                                   !8, ~26
  13    16        ASSIGN_DIM                                               !2, !7
        17        OP_DATA                                                  ''
  15    18        STRLEN                                           ~29     !4
        19        SUB                                              ~30     ~29, 1
        20        SUB                                              ~31     ~30, !6
        21        ASSIGN                                                   !9, ~31
  16    22        ASSIGN                                                   !10, 0
  17    23        STRLEN                                           ~34     !3
        24        SUB                                              ~35     ~34, 1
        25        ASSIGN                                                   !11, ~35
        26      > JMP                                                      ->62
  18    27    > > JMP                                                      ->32
  19    28    >   ASSIGN_CONCAT                               147          !2, !7
        29        OP_DATA                                                  '0'
  20    30        POST_DEC                                         ~38     !9
        31        FREE                                                     ~38
  18    32    >   IS_NOT_EQUAL                                     ~39     !9, 0
        33      > JMPNZ                                                    ~39, ->28
  23    34    >   FETCH_DIM_R                                      $40     !3, !11
        35        MUL                                              ~41     !8, $40
        36        ADD                                              ~42     ~41, !10
        37        ASSIGN                                                   !12, ~42
  24    38        STRLEN                                           ~44     !12
        39        IS_SMALLER                                       ~45     1, ~44
        40      > JMPZ_EX                                          ~45     ~45, ->43
        41    >   IS_NOT_EQUAL                                     ~46     !11, 0
        42        BOOL                                             ~45     ~46
        43    > > JMPZ                                                     ~45, ->54
  25    44    >   CAST                                          6  ~48     !12
        45        STRLEN                                           ~49     !12
        46        SUB                                              ~50     ~49, 1
        47        FETCH_DIM_R                                      $51     ~48, ~50
        48        ASSIGN_CONCAT                               147          !2, !7
        49        OP_DATA                                                  $51
  26    50        CAST                                          6  ~52     !12
        51        FETCH_DIM_R                                      $53     ~52, 0
        52        ASSIGN                                                   !10, $53
        53      > JMP                                                      ->60
  29    54    >   FETCH_DIM_R                                      $56     !3, !11
        55        MUL                                              ~57     !8, $56
        56        ADD                                              ~58     ~57, !10
        57        ASSIGN_CONCAT                               147          !2, !7
        58        OP_DATA                                                  ~58
  30    59        ASSIGN                                                   !10, 0
  17    60    >   POST_DEC                                         ~60     !11
        61        FREE                                                     ~60
        62    >   IS_SMALLER_OR_EQUAL                              ~61     0, !11
        63      > JMPNZ                                                    ~61, ->27
  34    64    >   FETCH_DIM_R                                      $62     !2, !7
        65        STRLEN                                           ~63     $62
        66        IS_SMALLER                                       ~64     !5, ~63
        67      > JMPZ                                                     ~64, ->70
  35    68    >   FETCH_DIM_R                                      $65     !2, !7
        69        ASSIGN                                                   !5, $65
  38    70    >   INIT_FCALL                                               'strrev'
        71        FETCH_DIM_R                                      $68     !2, !7
        72        SEND_VAR                                                 $68
        73        DO_ICALL                                         $69     
        74        ASSIGN_DIM                                               !2, !7
        75        OP_DATA                                                  $69
  10    76        POST_DEC                                         ~70     !6
        77        FREE                                                     ~70
        78    >   IS_SMALLER_OR_EQUAL                              ~71     0, !6
        79      > JMPNZ                                                    ~71, ->12
  41    80    >   ASSIGN                                                   !13, <array>
  42    81        ASSIGN                                                   !11, 0
        82      > JMP                                                      ->110
  43    83    >   ASSIGN                                                   !14, 0
  44    84        ASSIGN                                                   !6, 0
        85      > JMP                                                      ->103
  45    86    >   INIT_FCALL                                               'var_dump'
        87        FETCH_DIM_R                                      $76     !2, !6
        88        SEND_VAR                                                 $76
        89        DO_ICALL                                                 
  46    90        FETCH_DIM_IS                                     $78     !2, !6
        91        ISSET_ISEMPTY_DIM_OBJ                       33554432  ~79     $78, !11
        92        BOOL_NOT                                         ~80     ~79
        93      > JMPZ                                                     ~80, ->97
  47    94    >   FETCH_DIM_W                                      $81     !2, !6
        95        ASSIGN_DIM                                               $81, !11
        96        OP_DATA                                                  0
  49    97    >   FETCH_DIM_R                                      $83     !2, !6
        98        FETCH_DIM_R                                      $84     $83, !11
        99        CAST                                          4  ~85     $84
       100        ASSIGN_ADD                                    0          !14, ~85
  44   101        POST_INC                                         ~87     !6
       102        FREE                                                     ~87
       103    >   COUNT                                            ~88     !2
       104        IS_SMALLER                                       ~89     !6, ~88
       105      > JMPNZ                                                    ~89, ->86
  51   106    >   ASSIGN_DIM                                               !13, !11
       107        OP_DATA                                                  !14
  42   108        POST_INC                                         ~91     !11
       109        FREE                                                     ~91
       110    >   IS_SMALLER                                       ~92     !11, !5
       111      > JMPNZ                                                    ~92, ->83
  53   112    > > RETURN                                                   !13
  54   113*     > RETURN                                                   null

End of function stringmultiplicate

Generated using Vulcan Logic Dumper, using php 7.2.0