Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php in_array multiple values

Posted on 2013-01-01
4
Medium Priority
?
2,336 Views
Last Modified: 2013-01-01
Can you use in_array to see if an array contains multiple values.  Here is how I have been using it.

if (in_array("10527", $PayPalResult)) {
    $url_var = "card_number&card_type&";
}

Open in new window


how would I also check for the value 10510 in the same if statement?
0
Comment
Question by:Luey
  • 3
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38735127
If you look at the documentation, it demonstrates passing an array as the "needle". Just create a new array with the corresponding values being sought.

e.g.

$to_find = array("10527", "10510");

if (in_array($to_find, $PayPalResult)) {
    $url_var = "card_number&card_type&";
}

Open in new window

0
 

Author Comment

by:Luey
ID: 38735226
@ kaufmed   I have tried your code and cannot make it work.  I have looked at the documentation and agree that it should work according to the documentation. I can use either number (10527, 10510) by themselves and it works perfect.  But in the array it does not.  Any suggestions.  I know it is not my other codes because I have stripped it down to just this and it still does not work.
0
 

Author Closing Comment

by:Luey
ID: 38735309
This does work the way I asked the question.  However I need it to work more like an "or".  I need to know if 10527 or 10510 is in the array I cannot make it work for that.
0
 

Author Comment

by:Luey
ID: 38735351
This made it work like I needed it to.  

if (in_array("10527", $PayPalResult) or in_array("10510", $PayPalResult)) {
    $url_var = "card_number&card_type&";
}

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question