Php 开关功能变量未显示
我有一个switch函数,它假设获取在查询字符串中传递的参数的值,并根据它决定变量的值:Php 开关功能变量未显示,php,switch-statement,Php,Switch Statement,我有一个switch函数,它假设获取在查询字符串中传递的参数的值,并根据它决定变量的值: <?php switch($_REQUEST['textcolor']){ case "white": $textcolor = $white; break; case "black": $textcolor = $black; break; } ?> 这就是我有一个隐藏元素的形式;s假设显示值,但不显示: <form> <input type=
<?php
switch($_REQUEST['textcolor']){
case "white":
$textcolor = $white;
break;
case "black":
$textcolor = $black;
break;
}
?>
这就是我有一个隐藏元素的形式;s假设显示值,但不显示:
<form>
<input type="hidden" value="<?= $textcolor ?>">
</form>
$white和$black在哪里定义
编辑
做:
然后查看发生了什么在开关中添加最后一个案例
default:
die('textcolor is not '.$black.' or '.$white);
break;
之后的某处:$white=imagecolorallocate($Image22555255)$灰色=图像颜色($image2128128)$黑色=图像颜色分配($image2,0,0,0)代码>树ID在函数no go之前插入变量。必须在函数no go之前声明变量才能使用。如果在代码的后面定义了变量,则在需要它们的地方没有定义它们。。。。在你的转换声明中。在切换之前定义它们。正如您在上面所看到的,我尝试过,它仍然不起作用。什么是$white
或$black
?它们是以前声明的吗?请看下面的评论。以前尝试过声明它们,但没有成功。
switch($_REQUEST['textcolor']){
case "white":
$textcolor = $white;
break;
case "black":
$textcolor = $black;
break;
}
$white = 'white';
$black = 'black';
switch($_REQUEST['textcolor']){
case "white":
$textcolor = $white;
break;
case "black":
$textcolor = $black;
break;
}
default:
die('textcolor is not '.$black.' or '.$white);
break;