【发布时间】:2016-10-13 11:07:36
【问题描述】:
这里是我想要应用的 9 不同的字符串 if else 条件(or something better):
1. Automated - Under the Hood: iPhone 6 running iOS 9
2. Automated - AU/NZ: iPhone 6 running iOS 9
3. Automated - DRM: iPhone 6 running iOS 9
4. Automated - Ads regression: iPhone6 running iOS 9
5. Automated - Ads regression: iPhone 5 running iOS 8
6. Automated - UI & Functional Regression on iPad 2 running iOS 8
7. Automated - Under the Hood: iPad Air on iOS 8
8. Automated - AU/NZ: iPad Air running iOS 8
9. Automated - DRM iPadAir running iOS 8
每次,我都会得到一个above string,并将其分配给PHP variable。 It is possible that the order of words or position of few words in any string can change。但是某些东西,例如OS, phone type, OS version and test type will not change。根据字符串包含的具体单词,我将进行 REST api 调用。
例如,如果 PHP var 保存第一个字符串,即 if
$test = Automated - Under the Hood: iPhone 6 running iOS 9,然后我会进行#1 rest api 调用。
所以,我认为我应该这样做:
if ($test/string contains "under", "hood", "iPhone 6", "iOS 9") then do #1rest call (that i have command for)
else if ($test/string contains "AU", "NZ", "iPhone 6", "iOS 9") then do #2rest call..
....
else
... for all the above 9 strings.
到目前为止,我已经在 PHP 中尝试过 .contains()。 Will a switch be a better alternative to this? If yes, an example would be good to have. 否则,在 if-else 条件/正则表达式中做更好的方法。
【问题讨论】:
-
使用 in_array 函数对所有字符串进行数组检查
-
PHP 中的
contains()是什么? -
@ThomasAyoub:全部完成。
标签: php regex string parsing contains