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

Yes require the first file into the second. That’s all.

See an example below,

File1.php :

function first($int, $string){ //function parameters, two variables.
    return $string;  //returns the second argument passed into the function

Now Using require ( to require the File1.php to make its content available for use in the second file:

File2.php :

require __DIR__ . '/File1.php';
echo first(1, "omg lol"); //returns omg lol;

Leave a Comment