Conditional Comma-Separated Variables

I want to match numbers from a comma-separated string - bare in mind - if the value "1" is found the following statement should evaluate to true - but it doesn't. I would also like to make it so if the value "15" is found (and the functions searches for "1"), "15" will not return true just because there's a "1" in there. Here's what I've come up with... but, it doesn't work. (attached)
<?php 
$var = "1,2,3,15"; 
$explode = explode(",",$var); 
if (preg_match("1", $explode)) { 
 echo "A match was found."; 
} else { 
 echo "No match was found."; 
} 
?>

Open in new window

LVL 14
EMB01Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
<?php
$var = "1,2,3,15";
$explode = explode(",",$var);
if ( in_array(1,$explode) ) {
 echo "A match was found.";
} else {
 echo "No match was found.";
}
?>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hieloCommented:
alternatively:
<?php
$var = "1,2,3,15";

if (FALSE === strpos( ",".$var.",", "1") ) {
 echo "No match was found.";
} else {
 echo "A match was found.";
}
?>
0
EMB01Author Commented:
Thanks, I am quite unfamiliar with the in_array function and seldom use the numerious string functions... still learning. Thanks, again!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.