PHP Calculator Program using Switch statement
PHP Calculator Program using Switch statement.
Following four operations will perform in this calculator.
- Addition
- Subtraction
- Multiplication
- Division
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<!DOCTYPE html> <head> <title>Simple Calculator Program in PHP - Tutorials Class</title> </head> <?php $Number1 = $_POST['Number1']; $Number2 = $_POST['Number2']; $operator = $_POST['operator']; $ResultByT4Tutorials = ''; if (is_numeric($Number1) && is_numeric($Number2)) { switch ($operator) { case "Add": $ResultByT4Tutorials = $Number1 + $Number2; break; case "Subtract": $ResultByT4Tutorials = $Number1 - $Number2; break; case "Multiply": $ResultByT4Tutorials = $Number1 * $Number2; break; case "Divide": $ResultByT4Tutorials = $Number1 / $Number2; } } ?> <body> <div id="page-wrap"> <h1>Simple Calculator Program in PHP using Switch statement</h1> <form action="" method="post" id="quiz-form"> <p> <input type="number" name
="Number1" id="Number1" required="required" value="<?php echo $Number1; ?>" /> <b>First Number</b> </p> <p> <input type="number" name="Number2" id="Number2" required="required" value="<?php echo $Number2; ?>" /> <b>Second Number</b> </p> <p> <input readonly="readonly" name="ResultByT4Tutorials" value="<?php echo $ResultByT4Tutorials; ?>"> <b>ResultByT4Tutorials</b> </p> <input type="submit" name="operator" value="Addition" /> <input type="submit" name="operator" value="Subtract" /> <input type="submit" name="operator" value="Multiplication" /> <input type="submit" name="operator" value="Division" /> </form> </div> </body> </html> |
More Examples of Calculators
- PHP mortgage calculator script
- Age calculator in PHP
- GPA calculator in PHP
- Scientific calculator in PHP with database
- PHP grade calculator code
- PHP Calculator using Switch statement
- Calculator design in CSS and Javascript