简体   繁体   中英

php switch not functioning as intended

I am attempting to use the switch function of PHP but I must be doing something wrong. The code below will echo the result of the $find_top_type in the console but doesnt seem to go any further. I know the query is good having tested that and verified it through the ECHO. It doesnt seem to go further into the PHP however. It does not show me either of the other ECHO requests.

What am I doing wrong?

$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";
    }

我认为您应该添加 default 语句和 switch case 的结尾,并且您的 case 4 没有 break 语句。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM