note 91911 added to function.in-array
| From: | johnatdwarvendotcodotuk at osu1 dot php dot net | Date: | Wed, 01 Jul 2009 11:34:47 +0000 |
| Subject: | note 91911 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-157754@lists.php.net to get a copy of this message | ||
I just struggled for a while with this, although it may be obvious to others.
If you have an array with mixed type content such as:
<?php
$ary = array (
1,
"John",
0,
"Foo",
"Bar"
);
?>
be sure to use the strict checking when searching for a string in the array, or it will match on the
0 int in that array and give a true for all values of needle that are strings strings.
<?php
var_dump( in_array( 2, $ary ) );
// outputs FALSE
var_dump( in_array( 'Not in there', $ary ) );
// outputs TRUE
var_dump( in_array( 'Not in there', $ary, TRUE ) );
// outputs FALSE
?>
----
Server IP: 64.71.164.2
Probable Submitter: 89.105.107.98
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/91911
Del: integrated -- https://master.php.net/note/delete/91911/integrated
Del: useless -- https://master.php.net/note/delete/91911/useless
Del: bad code -- https://master.php.net/note/delete/91911/bad+code
Del: spam -- https://master.php.net/note/delete/91911/spam
Del: non-english -- https://master.php.net/note/delete/91911/non-english
Del: in docs -- https://master.php.net/note/delete/91911/in+docs
Del: other reasons-- https://master.php.net/note/delete/91911
Reject -- https://master.php.net/note/reject/91911
Search -- https://master.php.net/manage/user-notes.php