note 115821 deleted from function.in-array by sobak

From: Date: Sat, 25 Feb 2017 06:04:36 +0000
Subject: note 115821 deleted from function.in-array by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208841@lists.php.net to get a copy of this message
Note Submitter: Chaya Cooper ---- 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;

« previous php.notes (#208841) next »