Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http://phpmysql-academy.blogspot.in/
- Example: 1
- <?php
- function calc($num1, $num2, $op)
- {
- switch ($op)
- {
- case "+";
- $total = $num1 + $num2;
- break;
- case "-";
- $total = $num1 - $num2;
- break;
- case "*";
- $total = $num1 * $num2;
- break;
- case "/";
- $total = $num1 / $num2;
- break;
- default:
- echo "Unknown operator.";
- }
- }
- ?>
- Example: 2
- <?php
- function calc($num1, $num2, $op)
- {
- switch ($op)
- {
- case "+";
- $total = $num1 + $num2;
- break;
- case "-";
- $total = $num1 - $num2;
- break;
- case "*";
- $total = $num1 * $num2;
- break;
- case "/";
- $total = $num1 / $num2;
- break;
- default:
- echo "Unknown operator.";
- }
- calc(10,10,"+");
- }
- ?>
- Example: 3
- <?php
- function calc($num1, $num2, $op)
- {
- switch ($op)
- {
- case "+";
- $total = $num1 + $num2;
- break;
- case "-";
- $total = $num1 - $num2;
- break;
- case "*";
- $total = $num1 * $num2;
- break;
- case "/";
- $total = $num1 / $num2;
- break;
- default:
- echo "Unknown operator.";
- }
- echo calc(10,10,"+");
- }
- ?>
- Example: 4
- <?php
- function calc($num1, $num2, $op)
- {
- switch ($op)
- {
- case "+";
- $total = $num1 + $num2;
- return $total;
- break;
- case "-";
- $total = $num1 - $num2;
- return $total;
- break;
- case "*";
- $total = $num1 * $num2;
- return $total;
- break;
- case "/";
- $total = $num1 / $num2;
- return $total;
- break;
- default:
- echo "Unknown operator.";
- }
- echo calc(10,10,"+");
- }
- ?>
- Example: 5
- <?php
- function calc($num1, $num2, $op)
- {
- switch ($op)
- {
- case "+";
- $total = $num1 + $num2;
- return $total;
- break;
- case "-";
- $total = $num1 - $num2;
- return $total;
- break;
- case "*";
- $total = $num1 * $num2;
- return $total;
- break;
- case "/";
- $total = $num1 / $num2;
- return $total;
- break;
- default:
- echo "Unknown operator.";
- }
- }
- echo calc(10,10,"+");
- ?>
- Example: 6
- <?php
- function calc($num1, $num2, $op)
- {
- switch ($op)
- {
- case "+";
- $total = $num1 + $num2;
- return $total;
- break;
- case "-";
- $total = $num1 - $num2;
- return $total;
- break;
- case "*";
- $total = $num1 * $num2;
- return $total;
- break;
- case "/";
- $total = $num1 / $num2;
- return $total;
- break;
- default:
- echo "Unknown operator.";
- }
- }
- echo calc(13,7,"/");
- ?>
- Example:7
- <?php
- function calc($num1, $num2, $op)
- {
- switch ($op)
- {
- case "+";
- $total = $num1 + $num2;
- return $total;
- break;
- case "-";
- $total = $num1 - $num2;
- return $total;
- break;
- case "*";
- $total = $num1 * $num2;
- return $total;
- break;
- case "/";
- $total = $num1 / $num2;
- return $total;
- break;
- default:
- echo "Unknown operator.";
- }
- }
- echo calc(13,7,"a");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement