How to Call Function of One PHP File from Another PHP File and Pass Parameters to It

How to call php function from another file?

Change index.php as follows:

include "function.php";

(this is based on the assumption that both files are in the same directory, otherwise you have to add the filepath in the include line)

How to call a php function from another php file

Use the right kind of quotes around your string for the include. " or ' not and .

The use of typographic quotes like that suggests you may be trying to write code with a word processor. Don't do that; get a text or code editor instead.

How would I call a function in another file?

Include the file before you call the function.

include 'error-status.php';

Include a php file and call it from another php file

You can put all the code that's the same into an include file, e.g. common.php.


include 'common.php';


$a = 7;
$b = 8;
include 'common.php';

How do you conditionally call one php script from another with parameters

To pass control to a new script, you could use the header function. using this approach, you'd have to ensure that no other output is being generated by the first script prior to passing control, otherwise header will throw an error.

$var = 5;

header('Location:' . $var);


$varFrom1 = $_GET['var'];

Alternatively, I recommend using the include statement which lets you bring in another file and execute the functions contained therein

include '2.php';

$variable = "something";


You can reference it here:

Related Topics

Leave a reply