我有一个数组implode变量$ varString,它被设置为根据条件返回下面列出的3个单独的值。
If ($varString == 1)
{
echo 'APPLE';}
ElseIf ($varString == 2)
{
echo 'BANANA';}
ElseIf ($varString == 1,2) //throws an error.
{
echo 'APPLE and BANANA';}
如何处理1,2?
的情况我试过
ElseIf ($varString == '1,2') //throws an error.
{
echo 'APPLE and BANANA';}
ElseIf ($varString == "1,2") //throws an error.
{
echo 'APPLE and BANANA';}
答案 0 :(得分:1)
由于1,2只能被PHP理解为字符串,因此您应该将脚本更改为:
If ($varString == '1')
{
echo 'APPLE';
}
ElseIf ($varString == '2')
{
echo 'BANANA';
}
ElseIf ($varString == '1,2') //no it doesn't
{
echo 'APPLE and BANANA';
}
并且,字符串应始终位于''
答案 1 :(得分:0)
ElseIf ($varString == '1,2') { echo 'APPLE and BANANA';}