This article is a mirror article of machine translation, please click here to jump to the original article.

View: 9296|Reply: 0

declaration methods and call methods in PHP

[Copy link]
Posted on 2/24/2015 12:54:02 PM | | |

<?php

    This example is to let everyone know how to define a method in php and how to call it
   
    The following defines a method, which is very simple, that is, to deal with the addition problem of 2 numbers
    function add($number1, $number2) {
        
        $sum = $number1 + $number2;
        echo $sum;
    }
   
    Let's call the add() method   
    add(1,2);
   
    /**
    Note:
    function is the keyword that declares the method. The add after this keyword is the name of the method, and the parameters are in parentheses.
    It can also be without parameters. In brackets is the method. Inside is the logic of the method.
   
    The following add(1,2) is the call to add. If there is no call, the method will not be executed.
   
    */
   
   
    Define a method with a return value
   
    function re($n1, $n2) {
        
        $sum = $n1 + $n2;
        
        return $sum;
    }
   
    Call a method with a return value, call this method, the value is 5.
    echo re(2,3);
?>




Previous:Discuz removes the outer link of the waterproof wall
Next:php gets the IP address of the client
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com