Blogger Information
Blog 14
fans 0
comment 0
visits 8798
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
函数、数组、循环
于星辉
Original
613 people have browsed it

1.// 给定一个数组$arr = [23,3,45,6,78,8,34],筛选其偶数成员组成新的数组返回,请封装函数。```php
<?php
$arr = [23,3,45,6,78,8,34];

function shaixuan($arr){
foreach($arr as $k =>$v){
if($k % 2 == 0){
$newArr[]=$v;
}
}
return $newArr;
}
var_dump(shaixuan($arr));
?>

  1. 2. 尝试实现简单的计算器功能,语言不限制。
  2. ```php
  3. <?php
  4. $num1 = $_GET['num1'] ?? '请输入第一个数';
  5. $num2 = $_GET['num2'] ?? '请输入第二个数';
  6. $ysf = $_GET['con'] ?? '请选择运算符';
  7. $result= '';
  8. if (isset($ysf)){
  9. if ($ysf== '*'){
  10. $result = $num1 * $num2;
  11. }
  12. if($ysf == '/'){
  13. if($num2 != 0){
  14. $result = $num1 / $num2;
  15. }else{
  16. $result = '除数不能为零';
  17. }
  18. }
  19. if($ysf == '+'){
  20. $result =$num1 + $num2;
  21. }
  22. if($ysf == '-'){
  23. $result = $num1 - $num2;
  24. }
  25. }
  26. ?>
  27. <!DOCTYPE html>
  28. <html lang="en">
  29. <head>
  30. <meta charset="UTF-8">
  31. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  32. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  33. <title>计算器</title>
  34. </head>
  35. <body>
  36. <form action="" method="get">
  37. <input type="text" name= "num1">
  38. <br>
  39. <select name="con">
  40. <option value="+">+</option>
  41. <option value="-">-</option>
  42. <option value="*">*</option>
  43. <option value="/">/</option>
  44. <input type="text" name= "num2" >
  45. <br>
  46. <input type="submit" value="计算">
  47. <br>
  48. </form>
  49. </body>
  50. </html>
  51. <?= $result?>
Correcting teacher:灭绝师太灭绝师太

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post