我有这个PHP开关:
<?php
$destination = isset($_GET['act']);
switch ($destination) {
default:
echo "test";
break;
case "manage":
echo "manage things";
break;
case "create":
echo "create things";
break;
}
?>
Run Code Online (Sandbox Code Playgroud)
然而,当我去test.php?act=create,输出manage things不是create things....当我去test.php?act=manage- 当然我得到manage things...
那么......我该如何解决这个问题呢?谢谢
php的isset返回一个布尔值.所以$ destination是true还是false,而不是字符串.
尝试
if(isset($_GET['act']))
$destination = $_GET['act'];
Run Code Online (Sandbox Code Playgroud)