簡體   English   中英

in_array未產生預期結果

[英]in_array not produced expected results

一些使用in_array的簡單邏輯,但是我無法獲得預期的結果。 我期望這兩個IF語句都是正確的。 我只得到第二個(TRUE_TEST2)工作。

我對此有點loop! 我已經將var_dumpd的所有內容都看到了,可以看到它們都是11個字符的相同字符串。 為什么一個起作用而另一個不起作用?

謝謝

PHP代碼

        $follow_topics = get_user_meta(wp_get_current_user()->ID,'user_topic_follow');

        echo '1. '; var_dump($tracked_topic_slug);
        echo '2. '; var_dump('behavioural');
        echo '3. '; var_dump($follow_topics);

        echo '<br />';

        if( in_array($tracked_topic_slug, $follow_topics)) {echo 'TRUE_TEST1';}
        if( in_array('behavioural', $follow_topics)) {echo 'TRUE_TEST2';}

HTML輸出

    1.string 'behavioural' (length=11)

    2.string 'behavioural' (length=11)

    3. array (size=2)
      0 => string 'clinical' (length=8)
      1 => string 'behavioural' (length=11)

    TRUE_TEST2

看起來真的很奇怪。 您能告訴我們以下結果嗎?

var_dump('behavioural' === $tracked_topic_slug);
var_dump($tracked_topic_slug === $follow_topics[1]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM