Home  >  Article  >  Backend Development  >  PHP变量传递有关问题

PHP变量传递有关问题

WBOY
WBOYOriginal
2016-06-13 12:01:48865browse

PHP变量传递问题。
我include了一个a.PHP文件,使用a.PHP的变量,但我写了一个函数,在这个函数里就不能访问这个变量了,1、我用参数传递进去也没有用;2、我在函数里面include 了a.PHP,也是没有用。
请问函数怎么才可以访问这个外部文件a.PHP的变量?
------解决方案--------------------
不知道你config.php是怎樣寫,我試了一下,是可以拿到的,function a中 echo $TextTpl 改為 $textTpl 就可以了。

config.php

<br /><?php<br />$textTpl = '123';<br />?><br />


<br />include_once("config.php");<br />echo $textTpl; //123<br />$resultS= a($textTpl);  //无显示<br /><br />function a($textTpl){<br />  echo $textTpl; // 這裡改小寫,你之前用大寫了,當然不行<br />}<br />


輸出 123123
------解决方案--------------------

引用:
变量是区分大小写的!

官话就是:变量是大小写敏感的

还需要再提示一下,具体在下面找
<br />function a($textTpl) <br />{<br />  echo $TextTpl;<br /><br />}<br />
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn