【问题标题】:Getting variable from another file从另一个文件中获取变量
【发布时间】:2011-07-06 19:53:09
【问题描述】:

如何将变量从一个文件传递到另一个文件,但只有变量,而不是文件的输出(内容)。 ob_start 不适合我,还有什么?

【问题讨论】:

  • 不确定您的意思?显示一些代码可能会有所帮助
  • include('yourfile') 实际运行代码并设置变量?
  • 很不清楚你想要什么,有十几种方法可以解释这个问题。

标签: php variables include


【解决方案1】:

要传递一个变量,你需要包含你的文件

file1.php

<?php

$variable = "hello world";

?>

file2.php

<?php 
include ('file1.php')

echo $variable;
// hello world.

?>

这就是您将变量从一个文件传递到另一个文件的方式

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多