PHP if语句始终返回false

问题描述 投票:0回答:1

我正在使用带有简单if语句的PHP函数。如果变量= 100,则执行其他操作。

数据来自ACF Range Field。出于某种原因,即使ACF字段为= 100,该函数也会始终返回else语句。我发现问题是我尝试使用的if语句:=,==,!==,===或> =。如果将其更改为single =,则无论我在ACF Range字段中输入什么值,它总是返回h2,但其余所有返回h2。

function hovsa_shortcode() {
    $full_tegnet = get_field("tegnede_andele_");
    if ( $full_tegnet == '100' ) {

        return '<h2>Something</h2>';

    } else {

        return '<h2>Something else</h2>';

    }
}

add_shortcode( 'hovsa', 'hovsa_shortcode' );
php wordpress if-statement advanced-custom-fields equality
1个回答
0
投票

假设$full_tegnet应为整数,您可以使用以下

if(intval($full_tegnet) === 100){
     return '<h2>Something</h2>';
}
© www.soinside.com 2019 - 2024. All rights reserved.