php中的变量变量使用WAMP服务器问题
I am running newest version of WAMPServer on Windows 7 Home Premium. It accesses database (remote) fine, it runs basic PHP fine. My issue is with variable variables. On my godaddy server, the exact code runs fine.
When I try to include a file that uses variable variables (in this case $state{$i}) in WAMPServer says:
Notice: Undefined variable: state in E:\wamp\www\CCRN411\inc\state_drop_down.inc.php on line 2.
Note that it is looking for state, not state1 as the code generates for $i= 1 which I declare on the first line of the same file.
<select class="dropdownState" name="<?php $i=1; echo 'state' . $i; ?>" id="<?php echo 'state' . $i; ?>">
<option value="DL" <?php if ($state{$i} == "DL") {echo ('selected="selected"');} ?>>DELETE</option>
<option value="ZZ" <?php if ($state{$i} == "ZZ") {echo ('selected="selected"');} ?>>NONE</option>
If I add
$state1 = . and it is empty. What is the issue with my variable variable?
Help please.
我在Windows 7 Home Premium上运行最新版本的WAMPServer。 它访问数据库(远程)很好,它运行基本PHP很好。 我的问题是变量变量。 在我的godaddy服务器上,确切的代码运行正常。 p>
当我尝试在WAMPServer中包含一个使用变量变量的文件(在本例中为$ state {$ i})时说: p>
注意:未定义的变量:第2行的E:\ wamp \ www \ CCRN411 \ inc \ state_drop_down.inc.php中的状态。 p>
注意它 正在寻找状态,而不是state1,因为代码为$ i = 1生成,我在同一文件的第一行声明。 p>
&lt; select class =“dropdownState” name =“&lt;?php $ i = 1; echo'state'。$ i;?&gt;” id =“&lt;?php echo'state'。$ i;?&gt;”&gt;
&lt; option value =“DL”&lt;?php if($ state {$ i} ==“DL”){echo ('selected =“selected”');}?&gt;&gt; DELETE&lt; / option&gt;
&lt; option value =“ZZ”&lt;?php if($ state {$ i} ==“ZZ”){echo ('selected =“selected”');}?&gt;&gt; NONE&lt; / option&gt;
code> pre>
如果我添加
p> $ state1 =。 它是空的。
我的变量变量有什么问题? p>
请帮助。 p>
div>
Wrong syntax. You want ${"state$i"}
, as in
if (${"state$i"} == "DL") ...