如何从另一个PHP文件调用一个PHP文件的功能并将参数传递给它? [英] How to call function of one php file from another php file and pass parameters to it?

查看:605
本文介绍了如何从另一个PHP文件调用一个PHP文件的功能并将参数传递给它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从另一个PHP文件中的一个PHP文件中调用一个函数,并将两个参数传递给该函数.我该怎么办?

I want to call a function in one PHP file from a second PHP file and also pass two parameters to that function. How can I do this?

我对PHP非常陌生.所以请告诉我,我应该将第一个PHP文件包含在第二个PHP文件中吗?

I am very new to PHP. So please tell me, should I include the first PHP file into the second?

请给我举个例子.您可以根据需要提供一些链接.

Please show me an example. You can provide some links if you want.

推荐答案

是的,将第一个文件包含在第二个文件中.就是这样.

Yes include the first file into the second. That's all.

请参见下面的示例

File1.php:

File1.php :

<?php
  function first($int, $string){ //function parameters, two variables.
    return $string;  //returns the second argument passed into the function
  }
?>

现在使用include( http://php.net/include )来 include File1.php使其内容可在第二个文件中使用:

Now Using include (http://php.net/include) to include the File1.php to make its content available for use in the second file:

File2.php:

File2.php :

<?php
  include 'File1.php';
  echo first(1,"omg lol"); //returns omg lol;
?>

这篇关于如何从另一个PHP文件调用一个PHP文件的功能并将参数传递给它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆