note 126489 deleted from function.array-search by crell

From: Date: Thu, 31 Mar 2022 20:47:50 +0000
Subject: note 126489 deleted from function.array-search by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217965@lists.php.net to get a copy of this message
Note Submitter: jphansen at uga dot edu ---- Warning, array_search() and in_array() both search for values exactly matching the value of an element, and don't match if a value is within the value of an element. Example: $a = array("test"); if (array_search("te", $a) !== false) echo "found"; else echo "not found"; // outputs "not found" You'll need to iterate the array with a strpos() check if you'd like to search for a value within a value of an array. foreach ($a as $val) { if (strpos($val, "te") !== false) { echo "found" } } // outputs "found"

« previous php.notes (#217965) next »