变量不持有
我有一个带有 2 个变量的 .php 脚本。 $公司和$用户。在此 .php 脚本中,我 require_once "/var/www/etc/etc/etc/etc/"
我 require_once 的 .php 文件,前一个 .php 脚本中的变量不会转移过来。我不明白为什么,或者我做错了什么。前任。
master.php 脚本
$company = "Some Company";
$user = "John";
require_once "/var/www/$company/$user/example.php
example.php 脚本
$myFile = "/var/www/$company/$user/Template/Download/example.php";
变量 $company & 中保存的数据$user 没有坚持示例脚本。我不明白为什么。
谢谢
I have a .php script with 2 variables. $company and $user. During this .php script I require_once "/var/www/etc/etc/etc/etc/"
The .php file that I require_once, the variables from the previous .php script dont' transfer over. I can't figure out why, or what I am doing wrong. Ex.
master.php script
$company = "Some Company";
$user = "John";
require_once "/var/www/$company/$user/example.php
example.php script
$myFile = "/var/www/$company/$user/Template/Download/example.php";
The data that is held in the variables $company & $user doesn't hold through on the example script. I can't understand why.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果变量在其范围之外使用,则需要使用关键字“全球的”:
If variables are used outside their scope, you need to use the keyword "global":
您是否在新页面的函数内使用变量?如果是这种情况,那么您需要将它们注册为函数内的全局变量。否则,变量应该在从包含调用它们的脚本中正常读取。
Are you using the variables inside a function in the new page? If this is the case then you need to register them as global variables inside the function. Otherwise the variables should be read ok in the script calling them from the include.
你的变量是在函数内部吗?如果是这种情况,您可能会丢失变量。
在这种情况下,您必须在函数内使用“global”关键字,或者使用 $GLOBALS 变量来注册变量。
要真正查看变量是否正确传递,您可以
在文件 example.php 的顶部执行操作
Are your variables inside a function? if this is the case you probably lost your variables.
In this case, you would have to use either the "global" keyword inside the function, or use the $GLOBALS variable to register your variables.
To really see if your variables passed correctly, you can do
at the top of the file example.php