我想从我的index.php中调用我的自定义php函数,但该函数位于另一个文件中。何那么做?如何从另一个文件调用php函数?
例子:
的index.php:
<?php
myCustomFunction();
?>
function.php
<?php
function myCustomFunction(){
//some codes
}
?>
谢谢。
我想从我的index.php中调用我的自定义php函数,但该函数位于另一个文件中。何那么做?如何从另一个文件调用php函数?
例子:
的index.php:
<?php
myCustomFunction();
?>
function.php
<?php
function myCustomFunction(){
//some codes
}
?>
谢谢。
变化的index.php如下:
<?php
include "function.php";
myCustomFunction();
>?
(这是基于这样的假设两个文件都在同一个目录中,否则你必须添加的文件路径中include
线)
你只需要include
其他文件:
include('function.php');
index.php
:
<?php
include('function.php');
myCustomFunction();
PHP中include
功能就地插入包含传递给它的参数文件中的代码。
进一步的细节和替代,请参阅PHP手册:
http://php.net/manual/en/function.include.php
http://php.net/manual/en/function.include-once.php