note 86695 deleted from function.in-array by cmb
| From: | cmb@php.net | Date: | Mon, 21 Jan 2019 14:22:44 +0000 |
| Subject: | note 86695 deleted from function.in-array by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210089@lists.php.net to get a copy of this message | ||
Note Submitter: james dot ellis at gmail dot com
----
Be aware of oddities when dealing with 0 (zero) values in an array...
This script:
<?php
$array = array('testing',0,'name');
var_dump($array);
//this will return true
var_dump(in_array('foo', $array));
//this will return false
var_dump(in_array('foo', $array, TRUE));
?>
It seems in non strict mode, the 0 value in the array is evaluating to boolean FALSE and in_array
returns TRUE. Use strict mode to work around this peculiarity.
This only seems to occur when there is an integer 0 in the array. A string '0' will return
FALSE for the first test above (at least in 5.2.6).