我想检查一个给定的2个字符的值(我的输入: 一个列表是动态的(它将从我的数据库中读取),其中的值用逗号分隔 ,每个逗号后面有空格: p>
可以是例如: p>
第二个列表是我自己维护的静态列表,应该在 脚本本身。 p>
我不确定如何构建它。 也许只需定义一个变量,如: p>
如果 字符串匹配任何这些列表中的任何字符串,我只想输出该字符串,否则输出“不匹配”。 p>
最好和最快的方法是什么? p>
div> $ string code> ),存在于我的两个单独列表中的任何一个可能的匹配值: p>
$ dynamic_list =“AA,AB,BA”
$ dynamic_list =“BC”
$ dynamic_list =“”(空)
code> pre>
$ static_list =“MC,JL,EO”;
code> pre>
I want to check if a given 2-character value (my input: $string
), exists inside any of my two separate lists, of possible matching values:
One list is dynamic (it will be read from my DB), and the values in it are separated by commas, with space after each comma:
It can be for example:
$dynamic_list="AA, AB, BA"
$dynamic_list="BC"
$dynamic_list="" (Empty)
The second list is a static list that I will maintain myself, and should be within the script itself.
I’m not sure how to build it. Maybe just define a variable like:
$static_list="MC,JL,EO";
If the string matches any of the strings in any of those lists, I just want to output that string, otherwise output "no match".
What is the best and fast way to do this?