Home  >  Article  >  Backend Development  >  PHP encapsulation function steps

PHP encapsulation function steps

藏色散人
藏色散人Original
2019-11-09 10:09:124849browse

PHP encapsulation function steps

php encapsulation function steps

Define a method below. This method is very simple, it is to handle the addition of two numbers

    function add($number1, $number2) {
        $sum = $number1 + $number2;
        echo $sum;
    }
    //我们来调用add()方法    
    add(1,2);
   
    //定义一个带有返回值的方法
    function re($n1, $n2) {
        $sum = $n1 + $n2;
        return $sum;
    }
    //调用有返回值的方法,调用这个方法,值是5。
    echo re(2,3);

Explanation:

The function keyword is used to declare methods. The add after this keyword is the name of the method, and the parameters in parentheses are.

It can also have no parameters. Inside the braces is the method body. Inside is the logic of the method.

The add(1,2) below is to call the add method. The method will not be executed if it is not called.

Recommended: "PHP Tutorial"

The above is the detailed content of PHP encapsulation function steps. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:The core principle of phpNext article:The core principle of php