note 115820 added to function.in-array
| From: | ChayaCooper | Date: | Mon, 29 Sep 2014 22:32:29 +0000 |
| Subject: | note 115820 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200546@lists.php.net to get a copy of this message | ||
To identify all instances of $needle when both $needle and $haystack are arrays, combine in_array()
with a loop through the array of needles.
I've posted a functional example of it here: http://sandbox.onlinephpfunctions.com/code/930385800c30595129cefb87cfa7eec9d69dce08
$needles = array('John', 'Alex');
$haystack = array('John','Alexander','Kim', 'Michael');
foreach ($needles as $needle) {
// Displays var name & value currently searching for)
echo '$needle: '.$needle;
if (in_array($needle, $haystack) ) {
echo ', True; ';
}
else {
echo ', False; ';
}
}
Result is:
$needle: John, True; $needle: Alex, False;
----
Server IP: 72.52.91.14
Probable Submitter: 108.41.27.161
----
Manual Page -- http://php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/115820
Del: integrated -- https://master.php.net/note/delete/115820/integrated
Del: useless -- https://master.php.net/note/delete/115820/useless
Del: bad code -- https://master.php.net/note/delete/115820/bad+code
Del: spam -- https://master.php.net/note/delete/115820/spam
Del: non-english -- https://master.php.net/note/delete/115820/non-english
Del: in docs -- https://master.php.net/note/delete/115820/in+docs
Del: other reasons-- https://master.php.net/note/delete/115820
Reject -- https://master.php.net/note/reject/115820
Search -- https://master.php.net/manage/user-notes.php