I have a page with name 1.php
that has a function in it. Now I want to call the function in 2.php
in PHP 2. I wrote func();
this funct
Include the script that contains the function you need using the require_once()
method, like this:
require_once("../path/to/script.php");
Once you use the above method, PHP basically tacks the included script into the parent script, which will allow you to call functions, methods, and variables, as if they were in the parent script itself.
I would recommend require_once()
over include()
, include_once()
, or require()
, because this method will make sure that the script you are looking for exists, and is only called once. Calling the same script more than once (usually happening by accident) can cause strange problems in your script.
I hope that helps.