Home > Backend Development > PHP Problem > PHP encapsulation function steps

PHP encapsulation function steps

藏色散人
Release: 2023-02-28 12:54:02
Original
4993 people have browsed it

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);
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template