我需要我的脚本告诉我变量是否为数字,如果是,则是否为偶数。到目前为止我的代码:
$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";
}
我的浏览器显示空白页。
非常感谢任何帮助。
答案 0 :(得分:1)
语法错误。关闭foreach循环
$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";
}
}