dsmgcse8876 2013-10-27 06:37
浏览 29

如何回显爆炸阵列线

Here's the code.

<!DOCTYPE html>
<html>
<head><title>Numbers</title></head>
<body>
<form action="index.php" method="get">
<b>Numbers</b>
<br>
<textarea rows="12" cols="25" name="result" value="result"></textarea>
<br>
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>

<?php
$result=$_GET["result"];
if (empty($_GET['result']))
{
echo '<p><font size="3" color="red">Field is Empty*</font></p>';
}
elseif (isset($_GET['result']))
{
$result=(explode("
", $result));
}
{
echo count ($result);
echo "<br />";
echo array_sum($result);
}
?>

Ok so I figured out how to get most of my assignment's tasks and the last 1 that I am stuck with is using similar codes such as filter_var to print out non-numerical values that are submitted. Ex. a b c * & ! @

PRINTING any invalid inputs that aren't numbers. Ex. Letters, symbols.

Any suggestions?

  • 写回答

1条回答 默认 最新

  • duanmi3476 2013-10-27 08:58
    关注

    you can use the below code on your $result array & get the desired results:

    $oddArray = array();
    $evenArray = array();
    $skippedArray = array();
    
        foreach($result as $value)
       {
            if(is_numeric($value))
            {
               if($value%2 == 0)
               {
                   $evenArray[] = $value;
               }
               else
               {
                   $oddArray[] = $value; 
               }     
            }
            else
            {
                $skippedArray[] = $value;
            }   
    } 
    
    echo "Sum of odd values entered: ".array_sum($oddArray);
    echo "Sum of even values entered: ".array_sum($evenArray);
    echo "Skipped invalid values entered: ";
    print_r($skippedArray);
    

    I hope above will help you.

    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题