Searching for multiple values in an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tyler.pomroy
Forum Newbie
Posts: 8
Joined: Mon Sep 29, 2008 1:49 pm

Searching for multiple values in an array

Post by tyler.pomroy »

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.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Searching for multiple values in an array

Post by jaoudestudios »

Do in_array 3 times :D .

Store it in a database?

There must be a more efficient way! Than the above 2 suggestions I made.

Google?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Searching for multiple values in an array

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Searching for multiple values in an array

Post by jaoudestudios »

I knew you would have a solution :)
Post Reply