Copy CodeThe code is as follows:
/**php language is support object-oriented programming, for object-oriented programming, learn 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's keyword as "class".
Class Computer {
Inside a 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 a method in a class is to create an object of the class and invoke the method with the object
Here's how to call the class
*/
$com is the object of the computer class, creating the object with the New keyword
$com = new computer ();
Call a method in a class with the object name, the method name (parameters, Parameters ...). )
echo $com add;
Echo $com, JF;
echo $com CF (.)
These methods are called by the button, you can simply write a calculator,
Each button corresponds to a method
?>
http://www.bkjia.com/PHPjc/746865.html www.bkjia.com true http://www.bkjia.com/PHPjc/746865.html techarticle Copy the code as follows:? PHP/**php language is to support object-oriented programming, for object-oriented programming, learn Java and C + + people know Ah! * If not clear to Baidu ask ...