note 61672 added to function.array-search

From: Date: Thu, 09 Feb 2006 02:26:20 +0000
Subject: note 61672 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-103345@lists.php.net to get a copy of this message
may be good to take note of PHP's mind-boggling 'fuzzy' (vulgo "magic type-casting") comparison features not only in using the results, but also in the search, too: <?php $a=array("a","b",0,"c","d"); echo "a: ".array_search("a",$a); echo "b: ".array_search("b",$a); echo "c: ".array_search("c",$a); echo "d: ".array_search("d",$a); echo "0: ".array_search("0",$a); echo "x: ".array_search("x",$a); echo "1: ".array_search("1",$a); ?> will result in: a: 0, b: 1, c: 2, d: 2, 0: 2, x: 2, 1: false as from "c" on, the first match found in $a is "0", as any string compared to an int is automatically cast to (int)0. ---- Server IP: 212.124.37.9 Probable Submitter: 217.7.12.42 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61672 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61672&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61672&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61672&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61672&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61672&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61672&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61672&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61672&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103345) next »