3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('America/New_York'); function findInvestment($invest, $interest, $years) { // calculate the future value $future_value = $invest; for ($i = 1; $i <= $years; $i++) { $future_value = ($future_value + ($future_value * $interest *.01)); } // apply currency and percent formatting $investment_f = '$'.number_format($invest, 2); $yearly_rate_f = $interest.'%'; $future_value_f = '$'.number_format($future_value, 2); print(" <label>Investment Amount:</label> <span>$investment_f</span><br> <label>Yearly Interest Rate:</label> <span>$yearly_rate_f</span><br> <label>Number of Years:</label> <span>$years</span><br> <label>Future Value:</label> <span>$future_value_f</span><br> <h4>This calculation was done on " . date("m/d/Y").". "); } function printForm($print, $invest, $interest, $years) { if ($print == TRUE) { $invest = ""; $interest = ""; $years = ""; } else { if ( strlen($invest) == 0 ) { $error_message[] = 'Investment is a required field.'; } else if ( !is_numeric($invest) ) { $error_message[] = 'Investment must be a valid number.'; $invest = ""; } else if ( $invest <= 0 ) { $error_message[] = 'Investment must be greater than zero.'; } elseif ( strlen($interest) == 0 ) { $error_message[] = 'Interest rate is a required field.'; } else if ( !is_numeric($interest) ) { $error_message[] = 'Interest rate must be a valid number.'; $interest = ""; } else if ( $interest <= 0 OR $interest > 15 ) { $error_message[] = 'Interest rate must be greater than zero and less than or equal to 15.'; } elseif ( strlen($years) == 0 ) { $error_message[] = 'Years is a required field.'; } else if ( !is_numeric($years) ) { $error_message[] = 'Years must be a valid number.'; $years = ""; } else if ( $years <= 0 OR $years > 50 ) { $error_message[] = 'Years must be greater than zero and less than or equal to 50.'; } // set error message to empty string if no invalid entries else { $printResults = 1; $error_message = ''; } } print(" <!DOCTYPE html> <html> <head> <title>Future Value Calculator</title> <link href=\"main.css\" rel=\"stylesheet\" type=\"text/css\"> <meta charset=\"utf-8\"> </head> <body> <div id=\"content\"> <h1>Future Value Calculator</h1>"); if (!empty($error_message)) { foreach($error_message as $msg) { print("<p class=\"error\">$msg</p>"); } } else { $invest = ""; $interest = ""; $years = ""; } print("<form action=\"index.php\" method=\"post\"> <div id=\"data\"> <label>Investment Amount:</label> <input type=\"text\" name=\"investment\" value=\"$invest\"><br> <label class=\"clear\">Yearly Interest Rate:</label> <input type=\"text\" name=\"interest_rate\" value=\"$interest\"><br> <label class=\"clear\">Number of Years:</label> <input type=\"text\" name=\"years\" value=\"$years\"><br> </div> <div id=\"buttons\"> <label class=\"clear\">&nbsp;</label> <input type=\"submit\" value=\"Calculate\" name=\"submit\"><br> </div> </form>"); if (!empty($_POST['submit']) AND !$error_message) { findInvestment($_POST['investment'], $_POST['interest_rate'], $_POST['years']); } print("</div> </body> </html> "); } //if (empty($_POST['investment']) && empty($_POST['interest_rate']) && empty($_POST['years'])) { // printForm(1, "", "", ""); //} if (!empty($_POST['submit'])) { printForm(0, $_POST['investment'], $_POST['interest_rate'], $_POST['years']); } else { printForm(1, "", "", ""); } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 20
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SB6XF
function name:  (null)
number of ops:  27
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'date_default_timezone_set'
          1        SEND_VAL                                                 'America%2FNew_York'
          2        DO_ICALL                                                 
  113     3        FETCH_IS                                         ~1      '_POST'
          4        ISSET_ISEMPTY_DIM_OBJ                         1  ~2      ~1, 'submit'
          5        BOOL_NOT                                         ~3      ~2
          6      > JMPZ                                                     ~3, ->20
  114     7    >   INIT_FCALL                                               'printform'
          8        SEND_VAL                                                 0
          9        FETCH_R                      global              ~4      '_POST'
         10        FETCH_DIM_R                                      ~5      ~4, 'investment'
         11        SEND_VAL                                                 ~5
         12        FETCH_R                      global              ~6      '_POST'
         13        FETCH_DIM_R                                      ~7      ~6, 'interest_rate'
         14        SEND_VAL                                                 ~7
         15        FETCH_R                      global              ~8      '_POST'
         16        FETCH_DIM_R                                      ~9      ~8, 'years'
         17        SEND_VAL                                                 ~9
         18        DO_FCALL                                      0          
         19      > JMP                                                      ->26
  117    20    >   INIT_FCALL                                               'printform'
         21        SEND_VAL                                                 1
         22        SEND_VAL                                                 ''
         23        SEND_VAL                                                 ''
         24        SEND_VAL                                                 ''
         25        DO_FCALL                                      0          
  120    26    > > RETURN                                                   1

Function findinvestment:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 6
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 6
Branch analysis from position: 13
Branch analysis from position: 6
filename:       /in/SB6XF
function name:  findInvestment
number of ops:  43
compiled vars:  !0 = $invest, !1 = $interest, !2 = $years, !3 = $future_value, !4 = $i, !5 = $investment_f, !6 = $yearly_rate_f, !7 = $future_value_f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    7     3        ASSIGN                                                   !3, !0
    8     4        ASSIGN                                                   !4, 1
          5      > JMP                                                      ->11
    9     6    >   MUL                                              ~10     !3, !1
          7        MUL                                              ~11     ~10, 0.01
          8        ADD                                              ~12     !3, ~11
          9        ASSIGN                                                   !3, ~12
    8    10        PRE_INC                                                  !4
         11    >   IS_SMALLER_OR_EQUAL                                      !4, !2
         12      > JMPNZ                                                    ~15, ->6
   12    13    >   INIT_FCALL                                               'number_format'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 2
         16        DO_ICALL                                         $16     
         17        CONCAT                                           ~17     '%24', $16
         18        ASSIGN                                                   !5, ~17
   13    19        CONCAT                                           ~19     !1, '%25'
         20        ASSIGN                                                   !6, ~19
   14    21        INIT_FCALL                                               'number_format'
         22        SEND_VAR                                                 !3
         23        SEND_VAL                                                 2
         24        DO_ICALL                                         $21     
         25        CONCAT                                           ~22     '%24', $21
         26        ASSIGN                                                   !7, ~22
   16    27        ROPE_INIT                                     9  ~25     '%0A%09%09++++%3Clabel%3EInvestment+Amount%3A%3C%2Flabel%3E%0A%09%09%09%3Cspan%3E'
   18    28        ROPE_ADD                                      1  ~25     ~25, !5
         29        ROPE_ADD                                      2  ~25     ~25, '%3C%2Fspan%3E%3Cbr%3E%0A%0A%09%09%09%3Clabel%3EYearly+Interest+Rate%3A%3C%2Flabel%3E%0A%09%09%09%3Cspan%3E'
   21    30        ROPE_ADD                                      3  ~25     ~25, !6
         31        ROPE_ADD                                      4  ~25     ~25, '%3C%2Fspan%3E%3Cbr%3E%0A%0A%09%09%09%3Clabel%3ENumber+of+Years%3A%3C%2Flabel%3E%0A%09%09%09%3Cspan%3E'
   24    32        ROPE_ADD                                      5  ~25     ~25, !2
         33        ROPE_ADD                                      6  ~25     ~25, '%3C%2Fspan%3E%3Cbr%3E%0A%0A%09%09%09%3Clabel%3EFuture+Value%3A%3C%2Flabel%3E%0A%09%09%09%3Cspan%3E'
   27    34        ROPE_ADD                                      7  ~25     ~25, !7
         35        ROPE_END                                      8  ~24     ~25, '%3C%2Fspan%3E%3Cbr%3E%0A%09%09%09%3Ch4%3EThis+calculation+was+done+on+'
   28    36        INIT_FCALL                                               'date'
         37        SEND_VAL                                                 'm%2Fd%2FY'
         38        DO_ICALL                                         $30     
         39        CONCAT                                           ~31     ~24, $30
         40        CONCAT                                           ~32     ~31, '.%0A%09%09'
         41        ECHO                                                     ~32
   30    42      > RETURN                                                   null

End of function findinvestment

Function printform:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 91
Branch analysis from position: 82
2 jumps found. (Code = 77) Position 1 = 83, Position 2 = 89
Branch analysis from position: 83
2 jumps found. (Code = 78) Position 1 = 84, Position 2 = 89
Branch analysis from position: 84
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
2 jumps found. (Code = 46) Position 1 = 106, Position 2 = 108
Branch analysis from position: 106
2 jumps found. (Code = 43) Position 1 = 109, Position 2 = 120
Branch analysis from position: 109
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 120
Branch analysis from position: 108
Branch analysis from position: 89
Branch analysis from position: 91
2 jumps found. (Code = 46) Position 1 = 106, Position 2 = 108
Branch analysis from position: 106
Branch analysis from position: 108
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 45
2 jumps found. (Code = 47) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 53
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 59
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 68
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 68
2 jumps found. (Code = 47) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 76
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 91
Branch analysis from position: 82
Branch analysis from position: 91
Branch analysis from position: 72
Branch analysis from position: 49
filename:       /in/SB6XF
function name:  printForm
number of ops:  122
compiled vars:  !0 = $print, !1 = $invest, !2 = $interest, !3 = $years, !4 = $error_message, !5 = $printResults, !6 = $msg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   33     4        BOOL                                             ~7      !0
          5      > JMPZ                                                     ~7, ->10
   34     6    >   ASSIGN                                                   !1, ''
   35     7        ASSIGN                                                   !2, ''
   36     8        ASSIGN                                                   !3, ''
          9      > JMP                                                      ->78
   39    10    >   STRLEN                                           ~11     !1
         11        IS_EQUAL                                                 ~11, 0
         12      > JMPZ                                                     ~12, ->16
         13    >   ASSIGN_DIM                                               !4
         14        OP_DATA                                                  'Investment+is+a+required+field.'
         15      > JMP                                                      ->78
   40    16    >   INIT_FCALL                                               'is_numeric'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $14     
         19        BOOL_NOT                                         ~15     $14
         20      > JMPZ                                                     ~15, ->25
         21    >   ASSIGN_DIM                                               !4
         22        OP_DATA                                                  'Investment+must+be+a+valid+number.'
   41    23        ASSIGN                                                   !1, ''
         24      > JMP                                                      ->78
   42    25    >   IS_SMALLER_OR_EQUAL                                      !1, 0
         26      > JMPZ                                                     ~18, ->30
         27    >   ASSIGN_DIM                                               !4
         28        OP_DATA                                                  'Investment+must+be+greater+than+zero.'
         29      > JMP                                                      ->78
   44    30    >   STRLEN                                           ~20     !2
         31        IS_EQUAL                                                 ~20, 0
         32      > JMPZ                                                     ~21, ->36
         33    >   ASSIGN_DIM                                               !4
         34        OP_DATA                                                  'Interest+rate+is+a+required+field.'
         35      > JMP                                                      ->78
   45    36    >   INIT_FCALL                                               'is_numeric'
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                         $23     
         39        BOOL_NOT                                         ~24     $23
         40      > JMPZ                                                     ~24, ->45
         41    >   ASSIGN_DIM                                               !4
         42        OP_DATA                                                  'Interest+rate+must+be+a+valid+number.'
   46    43        ASSIGN                                                   !2, ''
         44      > JMP                                                      ->78
   47    45    >   IS_SMALLER_OR_EQUAL                              ~27     !2, 0
         46      > JMPNZ_EX                                         ~27     ~27, ->49
         47    >   IS_SMALLER                                       ~28     15, !2
         48        BOOL                                             ~27     ~28
         49    > > JMPZ                                                     ~27, ->53
         50    >   ASSIGN_DIM                                               !4
         51        OP_DATA                                                  'Interest+rate+must+be+greater+than+zero+and+less+than+or+equal+to+15.'
         52      > JMP                                                      ->78
   49    53    >   STRLEN                                           ~30     !3
         54        IS_EQUAL                                                 ~30, 0
         55      > JMPZ                                                     ~31, ->59
         56    >   ASSIGN_DIM                                               !4
         57        OP_DATA                                                  'Years+is+a+required+field.'
         58      > JMP                                                      ->78
   50    59    >   INIT_FCALL                                               'is_numeric'
         60        SEND_VAR                                                 !3
         61        DO_ICALL                                         $33     
         62        BOOL_NOT                                         ~34     $33
         63      > JMPZ                                                     ~34, ->68
         64    >   ASSIGN_DIM                                               !4
         65        OP_DATA                                                  'Years+must+be+a+valid+number.'
   51    66        ASSIGN                                                   !3, ''
         67      > JMP                                                      ->78
   52    68    >   IS_SMALLER_OR_EQUAL                              ~37     !3, 0
         69      > JMPNZ_EX                                         ~37     ~37, ->72
         70    >   IS_SMALLER                                       ~38     50, !3
         71        BOOL                                             ~37     ~38
         72    > > JMPZ                                                     ~37, ->76
         73    >   ASSIGN_DIM                                               !4
         74        OP_DATA                                                  'Years+must+be+greater+than+zero+and+less+than+or+equal+to+50.'
         75      > JMP                                                      ->78
   56    76    >   ASSIGN                                                   !5, 1
   57    77        ASSIGN                                                   !4, ''
   61    78    >   ECHO                                                     '%0A%09%09%09%3C%21DOCTYPE+html%3E%0A%09%09%09%3Chtml%3E%0A%09%09%09%09%3Chead%3E%0A%09%09%09%09%09%3Ctitle%3EFuture+Value+Calculator%3C%2Ftitle%3E%0A%09%09%09%09%09%3Clink+href%3D%22main.css%22+rel%3D%22stylesheet%22+type%3D%22text%2Fcss%22%3E%0A%09%09%09%09%09%3Cmeta+charset%3D%22utf-8%22%3E%0A%09%09%09%09%3C%2Fhead%3E%0A%09%09%09%0A%09%09%09%09%3Cbody%3E%0A%09%09%09%09%09%3Cdiv+id%3D%22content%22%3E%0A%09%09%09%09%09%09%3Ch1%3EFuture+Value+Calculator%3C%2Fh1%3E'
   73    79        ISSET_ISEMPTY_CV                                 ~42     !4
         80        BOOL_NOT                                         ~43     ~42
         81      > JMPZ                                                     ~43, ->91
   74    82    > > FE_RESET_R                                       $44     !4, ->89
         83    > > FE_FETCH_R                                               $44, !6, ->89
   75    84    >   ROPE_INIT                                     3  ~46     '%3Cp+class%3D%22error%22%3E'
         85        ROPE_ADD                                      1  ~46     ~46, !6
         86        ROPE_END                                      2  ~45     ~46, '%3C%2Fp%3E'
         87        ECHO                                                     ~45
   74    88      > JMP                                                      ->83
         89    >   FE_FREE                                                  $44
         90      > JMP                                                      ->94
   79    91    >   ASSIGN                                                   !1, ''
   80    92        ASSIGN                                                   !2, ''
   81    93        ASSIGN                                                   !3, ''
   83    94    >   ROPE_INIT                                     7  ~52     '%3Cform+action%3D%22index.php%22+method%3D%22post%22%3E%0A%09%09%09%09%09%09%09%3Cdiv+id%3D%22data%22%3E%0A%09%09%09%09%09%09%09%09%3Clabel%3EInvestment+Amount%3A%3C%2Flabel%3E%0A%09%09%09%09%09%09%09%09%3Cinput+type%3D%22text%22+name%3D%22investment%22+value%3D%22'
   86    95        ROPE_ADD                                      1  ~52     ~52, !1
         96        ROPE_ADD                                      2  ~52     ~52, '%22%3E%3Cbr%3E%0A%0A%09%09%09%09%09%09%09%09%3Clabel+class%3D%22clear%22%3EYearly+Interest+Rate%3A%3C%2Flabel%3E%0A%09%09%09%09%09%09%09%09%3Cinput+type%3D%22text%22+name%3D%22interest_rate%22+value%3D%22'
   89    97        ROPE_ADD                                      3  ~52     ~52, !2
         98        ROPE_ADD                                      4  ~52     ~52, '%22%3E%3Cbr%3E%0A%0A%09%09%09%09%09%09%09%09%3Clabel+class%3D%22clear%22%3ENumber+of+Years%3A%3C%2Flabel%3E%0A%09%09%09%09%09%09%09%09%3Cinput+type%3D%22text%22+name%3D%22years%22+value%3D%22'
   92    99        ROPE_ADD                                      5  ~52     ~52, !3
        100        ROPE_END                                      6  ~51     ~52, '%22%3E%3Cbr%3E%0A%09%09%09%09%09%09%09%3C%2Fdiv%3E%0A%0A%09%09%09%09%09%09%09%3Cdiv+id%3D%22buttons%22%3E%0A%09%09%09%09%09%09%09%09%3Clabel+class%3D%22clear%22%3E%26nbsp%3B%3C%2Flabel%3E%0A%09%09%09%09%09%09%09%09%3Cinput+type%3D%22submit%22+value%3D%22Calculate%22+name%3D%22submit%22%3E%3Cbr%3E%0A%09%09%09%09%09%09%09%3C%2Fdiv%3E%0A%09%09%09%09%09%09%3C%2Fform%3E'
        101        ECHO                                                     ~51
  101   102        FETCH_IS                                         ~56     '_POST'
        103        ISSET_ISEMPTY_DIM_OBJ                         1  ~57     ~56, 'submit'
        104        BOOL_NOT                                         ~58     ~57
        105      > JMPZ_EX                                          ~58     ~58, ->108
        106    >   BOOL_NOT                                         ~59     !4
        107        BOOL                                             ~58     ~59
        108    > > JMPZ                                                     ~58, ->120
  102   109    >   INIT_FCALL                                               'findinvestment'
        110        FETCH_R                      global              ~60     '_POST'
        111        FETCH_DIM_R                                      ~61     ~60, 'investment'
        112        SEND_VAL                                                 ~61
        113        FETCH_R                      global              ~62     '_POST'
        114        FETCH_DIM_R                                      ~63     ~62, 'interest_rate'
        115        SEND_VAL                                                 ~63
        116        FETCH_R                      global              ~64     '_POST'
        117        FETCH_DIM_R                                      ~65     ~64, 'years'
        118        SEND_VAL                                                 ~65
        119        DO_FCALL                                      0          
  105   120    >   ECHO                                                     '%3C%2Fdiv%3E%0A%09%09%09%09%3C%2Fbody%3E%0A%09%09%09%3C%2Fhtml%3E%0A%09%09'
  109   121      > RETURN                                                   null

End of function printform

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.02 ms | 1419 KiB | 24 Q