calc - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of calc.php
- <?php
- class MyCalculator {
- private $_fval, $_sval;
- public function __construct( $fval, $sval ) {
- $this->_fval = $fval;
- $this->_sval = $sval;
- }
- public function add() {
- return $this->_fval + $this->_sval;
- }
- public function subtract() {
- return $this->_fval - $this->_sval;
- }
- public function multiply() {
- return $this->_fval * $this->_sval;
- }
- public function divide() {
- return $this->_fval / $this->_sval;
- }
- }
- $mycalc = new MyCalculator(12, 6);
- echo $mycalc-> add()."\n"; // Displays 18
- echo $mycalc-> multiply()."\n"; // Displays 72
- echo $mycalc-> subtract()."\n"; // Displays 6
- echo $mycalc-> divide()."\n"; // Displays 2
- ?>
File Description
- calc
- PHP Code
- 17 Feb-2021
- 649 Bytes
You can Share it:
Latest PHP Pastes