2010-02-19 101 views
1

你好,我想知道如何從一些其他php頁面中定義的其他函數中調用一個php文件中定義的函數。從其他調用一個PHP函數?

+1

已經回答了無數時間:http://stackoverflow.com/search?q=calling+one+php+function+from+other和http://stackoverflow.com/search?q=include+files+php - 另外,請接受一些你回答15個問題滑到目前爲止。 – Gordon 2010-02-19 10:47:01

回答

3

做到這樣,
文件中,你需要調用的函數

 

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 
 
1

在其他PHP文件上使用include(),require()等,然後只需將函數名稱及其參數放在括號中即可。

3

首先,你需要包含這個文件或者使用

require_once or require 

include_once or include 

如果功能不上課,你會直接調用。

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

否則,你必須首先創建對象,比調用方法

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