note 87773 added to function.array-search

From: Date: Sun, 21 Dec 2008 01:23:43 +0000
Subject: note 87773 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-148397@lists.php.net to get a copy of this message
Expanding on the comment by hansen{}cointel.de: When searching for a string and the array contains 0 (zero), the string is casted to (int) by the type-casting which is always 0 (perhaps the opposite is the proper behaviour, the array value 0 should have been casted to string). That produces unexpected results if strict comparison is not used: <?php $a = array(0, "str1", "str2", "str3"); echo " str1 = ".array_search("str1", $a).", str2 = ".array_search("str2", $a).", str3 = ".array_search("str3", $a).", str1 strict = ".array_search("str1", $a, true).", str2 strict = ".array_search("str2", $a, true).", str3 strict = ".array_search("str3", $a, true); ?> This will return: str1 = 0, str2 = 0, str3 = 0, str1 strict = 1, str2 strict = 2, str3 strict = 3 ---- Server IP: 66.207.199.35 Probable Submitter: 207.6.224.210 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- https://master.php.net/note/edit/87773 Del: integrated -- https://master.php.net/note/delete/87773/integrated Del: useless -- https://master.php.net/note/delete/87773/useless Del: bad code -- https://master.php.net/note/delete/87773/bad+code Del: spam -- https://master.php.net/note/delete/87773/spam Del: non-english -- https://master.php.net/note/delete/87773/non-english Del: in docs -- https://master.php.net/note/delete/87773/in+docs Del: other reasons-- https://master.php.net/note/delete/87773 Reject -- https://master.php.net/note/reject/87773 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148397) next »