Copy Code code as follows:
<?php
/**php language is to support object-oriented programming, for object-oriented programming, Learning Java and C + + people know Ah!
* If you are not clear to Baidu to ask about it.
*/
Let's define a class that defines the class as the key word "class."
Class Computer {
Inside the class you can create methods, variables, etc.
Define an addition
function Add ($n 1, $n 2) {
$sum = $n 1 + $n 2;
return $sum;
}
Define a subtraction
function JF ($n 1, $n 2) {
$sum = $n 1-$n 2;
return $sum;
}
Define a multiplication
Function CF ($n 1, $n 2) {
$sum = $n 1 * $n 2;
return $sum;
}
}
/**
How to use the methods in the class, you create the object of the class, call the method with the object
Here's how to invoke a class
*/
$com is the object of the computer class, creating the object with the New keyword
$com = new computer ();
Calling methods in a class uses the object name-> the method name (parameters, Parameters ...). )
echo $com-> Add (1,2);
echo $com-> JF (1,2);
echo $com-> CF (1,2);
These methods are called by the button, you can simply write a calculator to
Each button corresponds to a method
?>