How to call a function in PHP in another form?

前端 未结 1 1152
北恋
北恋 2021-01-17 02:04

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

相关标签:
1条回答
  • 2021-01-17 02:41

    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.

    0 讨论(0)
提交回复
热议问题