Solved

php in_array multiple values

Posted on 2013-01-01
4
1,737 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now