简体   繁体   中英

why does in_array(0,*) always return 1

why would in_array(0, array("pop")) return 1?

see docs clearly 0 is not a value in the array and this should return 0 or FALSE.

in_array($needle, $haystack, $strict = FALSE) searches haystack for needle using loose comparison unless strict is set. When you don't provide third "strict" argument the values will be compared according to loose comparsion rules in php. Go to http://php.net/manual/en/types.comparisons.php . You'll see this loose comparison behavior documented.

0 == "pop" is a loose comparison returning TRUE

0 === "pop" is a strict comparison returning FALSE

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