note 61672 deleted from function.array-search by cmb
| From: | cmb@php.net | Date: | Sun, 01 Sep 2019 07:56:33 +0000 |
| Subject: | note 61672 deleted from function.array-search by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212076@lists.php.net to get a copy of this message | ||
Note Submitter: hansen{ä}cointel.de
----
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.