开发者

creating functions and using function calls in PHP

开发者 https://www.devze.com 2023-03-17 05:17 出处:网络
How would one go about creating a function file that is stored outside of the document root? I want to create a function that could accept 2 - 4 arguments and returns the sum of the arguments a开发者_

How would one go about creating a function file that is stored outside of the document root? I want to create a function that could accept 2 - 4 arguments and returns the sum of the arguments a开发者_如何学Cnd want it in an external file.


file1.php:

function funcName($var1, $var2, $var3, $var4)
{
    return $var1 + $var2 + $var3 + $var4;
}

file2.php:

include("file1.php");

print funcName(5, 15, 20, 10);

result of running file2.php:

50


Say your document root is /home/www/site, you can create a file under /home/www/lib and put your functions inside the file. After that you can include the function file from your other files using include or require directives:

include "/home/www/lib/your_func_file.php";
// Then you can call the function that is inside in your_func_file.php
your_func();

Read include manuel section and examine the examples.

0

精彩评论

暂无评论...
验证码 换一张
取 消