PHP - check if range appears in variable?


I have a variable like this :

$test = "002,003,004,005,012,032,045";

I'd like to see if any number in a range of numbers appears in this string.

eg :if ($test == [010-015]) echo "found";

this would check the $test variable for any number of 010,011,012,013,014,015 and if any is found then echo found.

How do I do this ?

Only way I can think of is to loop through each number .. but there must be a better way !





hope this helps you

$test = "002,003,004,005,012,032,045";
foreach (explode(',',$test) as $i)
  if($i > 10 && $i < 15)
    echo 'found';

People are also looking for solutions to the problem: while loop - How to display the serial number of the table rows in descending order in php?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.