从其他调用一个PHP函数?

从其他调用一个PHP函数?

问题描述:

你好,我想知道如何从一些其他php页面中定义的其他函数中调用一个php文件中定义的函数。从其他调用一个PHP函数?

+1

已经回答了无数时间:http://*.com/search?q=calling+one+php+function+from+other和http://*.com/search?q=include+files+php - 另外,请接受一些你回答15个问题滑到目前为止。 – Gordon 2010-02-19 10:47:01

做到这样,
文件中,你需要调用的函数

 

require_once("file_having_function_that_you_need_to_call.php"); 

function_name($arguments); // this function is defined in 'file_having_function_that_you_need_to_call.php' file 
 

在其他PHP文件上使用include(),require()等,然后只需将函数名称及其参数放在括号中即可。

首先,你需要包含这个文件或者使用

require_once or require 

include_once or include 

如果功能不上课,你会直接调用。

require("file.php"); 
echo getUserName("1") 

否则,你必须首先创建对象,比调用方法

require("file.php"); 
$obj = new User(); 
echo $obj->getUserName("1");