dounang1974
dounang1974
2014-10-11 19:32
浏览 42
已采纳

如何判断变量是否为数字以及是否为偶数? [关闭]

I need my script to tell me if a variable is numeric, and if it is, whether or not it's an even number. My code thus far:

        $Numbers = array("1", 2, "three", 4, 5, "six");

        foreach ($Numbers as $Value) {
            if (is_numeric($Value)) {
                if ($Value % 2 == 0) {
                    echo "$Value is numeric, and even";
                } else {
                    echo "$Value is numeric, but not even";
                }
            } else {
                echo "$Value is not numeric";
            }

My browser is displaying a blank page.

Any help would be greatly appreciated.

图片转代码服务由CSDN问答提供 功能建议

我需要我的脚本告诉我变量是否为数字,如果是,则是否为偶数 数。 到目前为止我的代码:

  $ Numbers = array(“1”,2,“three”,4,5,“six”); 
 
 foreach($ 数字为$ Value){
 if(is_numeric($ Value)){
 if($ Value%2 == 0){
 echo“$ Value是数字,甚至是”; 
}其他{
  echo“$ Value是数字,但不是偶数”; 
} 
} else {
 echo“$ Value不是数字”; 
} 
   
 
 

我的浏览器显示空白页面。

我们非常感谢任何帮助。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzhiyong8577
    dongzhiyong8577 2014-10-11 19:38
    已采纳

    Syntax error.Close foreach loop

     $Numbers = array("1", 2, "three", 4, 5, "six");
    
            foreach ($Numbers as $Value)
            {
                if (is_numeric($Value))
                {
                    if ($Value % 2 == 0)
                    {
                        echo "$Value is numeric, and even";
                    }
                    else
                    {
                        echo "$Value is numeric, but not even";
                    }
                }
                else
                {
                    echo "$Value is not numeric";
                }
    }
    
    点赞 评论

相关推荐