Checking for multiple strpos values

Chad Cardiff picture Chad Cardiff · Oct 6, 2013 · Viewed 37.3k times · Source

I am wondering how to complete multiple strpos checks.

Let me clarify:
I want strpos to check the variable "COLOR" to see if any numbers from 1 to 8 are anywhere in the variable. If any numbers from 1 to 8 are present, I want to echo "selected".

Examples:
Let's say only the number 1 is in the variable, it will echo "selected".
Let's say the numbers 1 2 and 3 are in the variable, it will echo "selected."
Let's say the numbers 3 9 25 are in the variable, it will echo "selected" (because of that 3!!).
Let's say only the number 9 is in the variable, it will NOT echo.
Let's say the numbers 9 25 48 are in the variable, it will NOT echo.

Answer

Chad Cardiff picture Chad Cardiff · Oct 6, 2013

I just used the OR statement (||)

<?php 
  if (strpos($color,'1') || strpos($color,'2') || strpos($color,'3') || strpos($color,'4') || strpos($color,'5') || strpos($color,'6') || strpos($color,'7') || strpos($color,'8') === true) 
   {
    //do nothing
   } else { 
            echo "checked"; 
          } 
?>