note 126489 added to function.array-search

From: Date: Fri, 08 Oct 2021 19:18:26 +0000
Subject: note 126489 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-217049@lists.php.net to get a copy of this message
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" ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 128.192.33.3) ---- Manual Page -- https://php.net/manual/en/function.array-search.php Edit -- https://main.php.net/note/edit/126489 Del: integrated -- https://main.php.net/note/delete/126489/integrated Del: useless -- https://main.php.net/note/delete/126489/useless Del: bad code -- https://main.php.net/note/delete/126489/bad+code Del: spam -- https://main.php.net/note/delete/126489/spam Del: non-english -- https://main.php.net/note/delete/126489/non-english Del: in docs -- https://main.php.net/note/delete/126489/in+docs Del: other reasons-- https://main.php.net/note/delete/126489 Reject -- https://main.php.net/note/reject/126489 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217049) next »