如何从另一个文件调用php函数?

如何从另一个文件调用php函数?,php,Php,我想从index.php调用自定义php函数,但该函数位于另一个文件中。怎么做 例如: index.php: <?php myCustomFunction(); ?> function.php <?php function myCustomFunction(){ //some codes } ?> 谢谢。您只需要包含另一个文件: include('function.php'); index.php: <?php include('functi

我想从index.php调用自定义php函数,但该函数位于另一个文件中。怎么做

例如:

index.php:

<?php

myCustomFunction();

?>

function.php

<?php

function myCustomFunction(){
//some codes
}

?>


谢谢。

您只需要
包含另一个文件:

include('function.php');
index.php

<?php

include('function.php');

myCustomFunction();

更改index.php如下:

<?php
  include "function.php";
  myCustomFunction();
?>

(这是基于两个文件位于同一目录的假设,否则必须在
include
行中添加文件路径)