Sandy
Sandy

Reputation: 14135

calling one php function from other?

hello i want to know how to call a function defined in one php file from some other function defined in some other php page.

Upvotes: 1

Views: 1159

Answers (3)

Gaurav Sharma
Gaurav Sharma

Reputation: 2848

do like this,
in the file where you need to call the function


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

Upvotes: 3

Adeel
Adeel

Reputation: 19238

First you need to include that file either using

require_once or require

or

include_once or  include

if the function is not in class, you will call directly.

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

otherwise you have to first create object and than call method

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

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799400

Use include(), require(), etc. on the other PHP file, then just put the function name followed by its arguments in parentheses.

Upvotes: 1

Related Questions