Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次の配列があるとします。
$enabled = array( 'page' => 'page', 'article' => 0, );
「記事」はキーであり、値ではないことに注意してください。一致する値を検索するためin_array()、次の行は FALSE を返すと予想されます。
in_array()
in_array('article', $enabled)
それでも、TRUE を返します。なんで?私は何が欠けていますか?
厳密な型チェックのために 3 番目のパラメーターを渡します。
in_array('article', $enabled, true);
0それ以外の場合、PHP は(整数) と'article'(文字列)を比較しようとします。 → 'article'0 に評価されます! →対等です!
0
'article'
例 @ codepad.org