This article mainly introduces the PHP class declaration and the PHP class uses the method example, needs the friend to be possible to refer to under
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. / //We define a class, the keyword of the definition class is "class" class computer { //within class can create methods, variables etc //define an addition &NB Sp function Add ($n 1, $n 2) { $sum = $n 1 + $n 2; &N Bsp return $sum; } //define a subtraction function JF ($n 1, $n 2) { $sum = $n 1-$n 2; &N Bsp 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 need to create the object of the class, use the object to invoke the method Below is the method to invoke the class / / /$com is the object of the computer class, creating objects with the New keyword $com = new computer (); //calling methods in the class with object name-> method name (parameter, parameter ...) ) 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, //each button corresponding to a method?>