批改状态:合格
老师批语:这样的作业标题并不合适, 毕竟是公开发表的博客, 下次注意
<?php$arr = [23,1,25,7,23,7,12];$arr7=[];function arr($arr,$arr7){for ($i = 0; $i <count($arr);$i++){//print($arr[$i]);if(($arr[$i]%2)==1){array_push($arr7,$arr[$i]);}echo "<br>";}print_r($arr7);}arr($arr,$arr7);?>
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>计算器</title></head><body><?phperror_reporting(E_ALL & ~E_NOTICE);if(isset($_POST['sub'])):if($_POST['opt'] == '/' && $_POST['num2'] == 0 || $_POST['opt'] == '%' && $_POST['num2'] == 0) $mess = "<span style='color:red;'>oops~除数不能为0</span>";endif;?><h1>计算器</h1><table><form action="" method="post"><tr><td><input type="number" name="num1" required value="<?=$_POST['num1']?>"></td><td><select name="opt"><option value="+" <?=$_POST["opt"] == "+" ? "selected" : "" ?> >+</option><option value="-" <?=$_POST["opt"] == "-" ? "selected" : "" ?>>-</option><option value="*" <?= $_POST["opt"] == "*" ? "selected" : "" ?>>*</option><option value="/" <?= $_POST["opt"] == "/" ? "selected" : "" ?>>/</option><option value="%" <?= $_POST["opt"] == "%" ? "selected" : "" ?>>%</option></select></td><td><input type="number" name="num2" required value="<?=$_POST['num2']?>" ></td><td><input type="submit" name="sub" value="计算"></td></tr></form><?phpif(!$mess && isset($_POST['sub']) ):switch($_POST['opt']):case "+":$sum = (int)$_POST['num1'] + (int)$_POST['num2'];break;case "-":$sum = (int)$_POST['num1'] - (int)$_POST['num2'];break;case "*":$sum = (int)$_POST['num1'] * (int)$_POST['num2'];break;case "/":$sum = (int)$_POST['num1'] / (int)$_POST['num2'];break;case "%":$sum = (int)$_POST['num1'] % (int)$_POST['num2'];break;endswitch;$res = "计算结果:{$_POST['num1']} {$_POST['opt']} {$_POST['num2']} = {$sum}";echo "<span style='color:green;'>{$res}</span>";else:echo $mess;endif;?></table></body></html>
计算器我还没有熟练掌握,我会继续学习的加油。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号