note 97237 rejected from function.array-search by danbrown
| From: | danbrown@php.net | Date: | Fri, 09 Apr 2010 13:37:46 +0000 |
| Subject: | note 97237 rejected from function.array-search by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168080@lists.php.net to get a copy of this message | ||
Note Submitter: r dot wilczek at web-appz dot de
----
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.