note 61491 added to function.in-array
| From: | kitchin at osu1 dot php dot net | Date: | Sun, 05 Feb 2006 14:52:47 +0000 |
| Subject: | note 61491 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103036@lists.php.net to get a copy of this message | ||
Here's a gotcha, and another reason to always use strict with this function.
$x= array('this');
$test= in_array(0, $x);
var_dump($test); // true
$x= array(0);
$test= in_array('that', $x);
var_dump($test); // true
$x= array('0');
$test= in_array('that', $x);
var_dump($test); // false
It's hard to think of a reason to use this function *without* strict.
This is important for validating user input from a set of allowed values, such as from a
<select> tag.
----
Server IP: 64.246.30.37
Probable Submitter: 65.147.139.50
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61491
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61491&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61491&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61491&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61491&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61491&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61491&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61491&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61491&report=yes
Search -- http://master.php.net/manage/user-notes.php