Jump to content

Array question


farsighted

Recommended Posts

Hey,

 

I'm really new to php, and coding in general, so please forgive me if anything I say is dumb. What I'm trying to do is this:

I have a variable ($variable) that I want to compare to the instances of an array ($values) using an if/else statement like this:

if ($variable == $values) {

code to be executed

 

What I need to know is, how do I compare the variable to all the instances of the array? Would I have to use a loop function? If so, I'd need to be pointed in the right direction... Or can I just do something like:

if ($variable == $values[0, 1 ,2]) { //I know that doesn't work, but is there some sort of way like that to do it? Is there a way of saying if ($variable == $values[0] or $values[0] or $values[0]) {

code to be executed

 

Thanks

Shane

Link to comment
https://forums.phpfreaks.com/topic/116010-array-question/
Share on other sites

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.