检查多个strpos值 [英] Checking for multiple strpos values

查看:345
本文介绍了检查多个strpos值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何完成多个strpos检查.

I am wondering how to complete multiple strpos checks.

让我澄清一下:
我希望strpos检查变量"COLOR",以查看变量中是否存在1到8之间的任何数字.如果存在1到8之间的任何数字,我想回显已选择".

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".

示例:
假设变量中只有数字1,它会回显已选择".
假设数字1 2和3在变量中,它回显已选中".
假设数字3 9 25在变量中,它会回显"selected"(因为这3个!).
假设变量中只有数字9,它不会回显.
假设数字9 25 48在变量中,它不会回显.

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.

推荐答案

我刚刚使用了OR语句(||)

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"; 
          } 
?>

这篇关于检查多个strpos值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆