简体   繁体   English

in_array未产生预期结果

[英]in_array not produced expected results

Some simple logic using in_array but I cannot get the expected result. 一些使用in_array的简单逻辑,但是我无法获得预期的结果。 I am expecting both IF statements to be true. 我期望这两个IF语句都是正确的。 I only get the second (TRUE_TEST2) to work. 我只得到第二个(TRUE_TEST2)工作。

I am going a bit loopy on this! 我对此有点loop! I have var_dump'd everything and can see they are both identical strings of 11 chars. 我已经将var_dumpd的所有内容都看到了,可以看到它们都是11个字符的相同字符串。 Why will one work and not the other? 为什么一个起作用而另一个不起作用?

Thanks 谢谢

PHP Code 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 OUTPUT 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

Looks really weird. 看起来真的很奇怪。 Can you show us result of this: 您能告诉我们以下结果吗?

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