【发布时间】:2020-10-12 02:09:16
【问题描述】:
我正在尝试使用 PHP 的 switch 功能,但我一定是做错了什么。下面的代码将在控制台中回显 $find_top_type 的结果,但似乎没有更进一步。我知道这个查询很好,已经测试并通过 ECHO 验证了它。然而,它似乎并没有深入到 PHP 中。它没有向我显示任何其他 ECHO 请求。
我做错了什么?
$find_top_type = $wpdb->get_var($wpdb->prepare("SELECT column_1 FROM mytable WHERE id = $tid"));
echo $find_top_type;
$find_top_type = 2;
$find_top_type = 4;
$find_top_type = 6;
$find_top_type = 8;
switch($find_top_type){
case 2:
echo "retuning two test";
break;
case "4":
echo "retuning four test";
}
【问题讨论】:
-
switch前4个赋值语句的作用是什么?
-
你没有得到任何输出,因为你最后硬编码了
find_top_type =8,没有8的情况。尝试先学习基本概念。 php.net/manual/en/control-structures.switch.php -
@musa 他们正在定义开关,不是吗?这些是条件
-
如果我理解正确的话 = X 就是它要找的东西?
-
不,你用等号赋值。
标签: php switch-statement