How to call function of one php file from another php file and pass parameters to it?

前端 未结 4 963
滥情空心
滥情空心 2020-12-07 19:46

I want to call a function in one PHP file from a second PHP file and also pass two parameters to that function. How can I do this?

I am very new to PHP. So please te

4条回答
  •  渐次进展
    2020-12-07 20:20

    files directory:

    Project->

    -functions.php

    -main.php

    functions.php

    function sum(a,b){
     return a+b;
    }
    function product(a,b){
    return a*b;
    }
    

    main.php

    require_once "functions.php";
    echo "sum of two numbers ". sum(4,2);
    echo "
    "; // create break line echo "product of two numbers ".product(2,3);

    The Output Is :

    sum of two numbers 6 product of two numbers 6

    Note: don't write public before function. Public, private, these modifiers can only use when you create class.

提交回复
热议问题