/    Sign up×
Community /Pin to ProfileBookmark

comparing values to values in an array

Hi,

I have some validation to do,

I have a set of values in the form b1, b2, b3, b4, w1, w25, w3, w4, etc.

I figured that I could put all these values in an array so that I can then compare an inputted value to the array, but am unsure exactly how to do it

$numberArray = array(“b1”, “b2”, “b3”, “b4”, “w1”, “w25”, “w3”, “w4”);

then if I have another variable $inputNumber, how do I compare this to the array, i.e. check if it is in the array?

thanks a lot

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 09.2004 — [url=http://us4.php.net/manual/en/function.in-array.php]in_array()[/url]:
[code=php]
if(in_array($some_value, $your_array))
{
# value is in array, so do this
}
else
{
# value is not in array, so do something else
}
[/code]
×

Success!

Help @damon2003 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...