Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To check for multiple values using in_array in PHP, you need to pass an array of values as the needle parameter, and use a loop or array function to check each value. Here is an example:

$values = array('apple', 'banana', 'orange');
$search = array('pear', 'banana');

foreach ($search as $item) {
    if (in_array($item, $values)) {
        echo $item . ' found';
    } else {
        echo $item . ' not found';
    }
}

In this example, we have an array $values with three fruit names, and another array $search with two fruit names. We loop through the $search array and use in_array to check if each item is found in the $values array. If a value is found, we print a message saying that it was found, otherwise we print a message saying that it was not found.