dongyinpan9284 2016-11-25 13:16
浏览 186
已采纳

我可以在另一个包含的文件中使用包含文件的变量吗?

Hello let me explain my question. I'm using PHP at the moment and I'm just playing around a bit now im wondering if I have a file for example:

//This is file1.php
<?php
$text = "Hello";
?>

And include it in file2 and also include file3:

//This is file2.php
<?php
include 'file1.php';
include 'file3.php';
?>

Now Comes my question can I use $text in file3 like so?:

//This is file3.php
<?php
echo $text;
?>

Thank you for your response!

  • 写回答

1条回答 默认 最新

  • doudao8283 2016-11-25 13:19
    关注

    Short ans quick: Yes you can, but NOT in your example. If you call $text in your file2 after including it, it works.

    Include does the same, as you have the code in the same file. But look at the order, its important.

    Build one file you call over the browser and require all you need in this file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用