【发布时间】:2011-10-05 05:02:51
【问题描述】:
我只是想不出代码。我有太多的 if 语句要更改为 switch 语句,但我找不到逻辑。
目前我有:
if(strstr($var,'texttosearch'))
echo 'string contains texttosearch';
if(strstr($var,'texttosearch1'))
echo 'string contains texttosearch1';
if(strstr($var,'texttosearch2'))
echo 'string contains texttosearc2h';
//etc etc...
但是我怎样才能在 switch 中实现同样的效果呢?
【问题讨论】:
-
其实
foreach解决方案php-coder更好用switch。它将减少代码行。
标签: php switch-statement strstr