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

前端 未结 4 955
滥情空心
滥情空心 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:01

    you can write the function in a separate file (say common-functions.php) and include it wherever needed.

    function getEmployeeFullName($employeeId) {
    // Write code to return full name based on $employeeId
    }
    

    You can include common-functions.php in another file as below.

    include('common-functions.php');
    echo 'Name of first employee is ' . getEmployeeFullName(1);
    

    You can include any number of files to another file. But including comes with a little performance cost. Therefore include only the files which are really required.

提交回复
热议问题