Jump to content

[SOLVED] Searching for multiple values in an array


unrelenting

Recommended Posts

I can't figure out how to do this.

 

I have an array for example:

 

$colors = array("red", "green", "blue", "orange", "purple", "yellow");

 

I have used in_array in the past to do this for a single value but what if I am wanting to check is if red, orange, AND yellow all show up in the array somewhere? How would I do that?

 

Thanks.

<?php
$colors = array("red", "green", "blue", "orange", "purple", "yellow");
$find = array("red", "orange", "yellow");
$found = count($find); //3
foreach($find as $f)
{
if(in_array($f, $colors))
{
	found--;
}
}
if(found==0) echo "Found all";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.