note 97237 added to function.array-search
| From: | r dot wilczek at web-appz dot de | Date: | Fri, 09 Apr 2010 13:24:40 +0000 |
| Subject: | note 97237 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168079@lists.php.net to get a copy of this message | ||
Note on the above documentation: "If the third parameter strict is set to TRUE then the
array_search() function will also check the types of the needle in the haystack."
If the array contains objects, setting the strict-parameter to TRUE will check for object-identity,
not only for equality of type and value!
<?php
$foo = new stdClass; $foo->foo = 'a';
$bar = new stdClass; $bar->foo = 'a';
var_dump(array_search($bar, array($foo))); // int(0)
var_dump(array_search($bar, array($foo), true)); // bool(false)
?>
If the comparison would check for equality of type and value only,
the strict variant would output int(0), for $foo and $bar in the example
do not differ in both type and value.
----
Server IP: 217.160.235.204
Probable Submitter: 80.153.202.193
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/97237
Del: integrated -- https://master.php.net/note/delete/97237/integrated
Del: useless -- https://master.php.net/note/delete/97237/useless
Del: bad code -- https://master.php.net/note/delete/97237/bad+code
Del: spam -- https://master.php.net/note/delete/97237/spam
Del: non-english -- https://master.php.net/note/delete/97237/non-english
Del: in docs -- https://master.php.net/note/delete/97237/in+docs
Del: other reasons-- https://master.php.net/note/delete/97237
Reject -- https://master.php.net/note/reject/97237
Search -- https://master.php.net/manage/user-notes.php