Blogger Information
Blog 52
fans 1
comment 1
visits 38795
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用定界符heredoc输出九格宫表格
小丑0o鱼
Original
408 people have browsed it
  1. $html = <<<EOF
  2. {$htmls}
  3. EOF;
  4. function randColor (){
  5. $colors = array();
  6. for($i = 0;$i<6;$i++){
  7. $colors[] = dechex(rand(0,15));
  8. }
  9. return '#'.implode('',$colors);
  10. };
  11. function htmls($a,$b)
  12. {
  13. echo '<table>';
  14. for ($i=1; $i<=$a; $i++) {
  15. echo '<tr>';
  16. for ($j=1; $j<=$b; $j++) {
  17. echo '<td style="height: 50px; width: 50px; background-color:'.randColor().'">1</td>';
  18. }
  19. echo '</tr>';
  20. }
  21. echo '</table>';
  22. }
  23. $htmls = htmls(3,3);
  24. echo $html;
  25. 2.php实现具有简单功能的计算器
  26. // 通过POST取值
  27. $left = $_POST['left'] ?? 0;
  28. $right = $_POST['right'] ?? 0;
  29. $operator = $_POST['operator'];
  30. // 计算函数
  31. function total($a = 0, $b = 0, $opt = '+')
  32. {
  33. switch ($opt):
  34. case '+':
  35. return $a + $b;
  36. case '-':
  37. return $a - $b;
  38. case '*':
  39. return $a * $b;
  40. case '/':
  41. return $a / $b;
  42. endswitch;
  43. }
  44. // 调用函数并赋值
  45. $total = total($left, $right, $operator) ?? 0;
  46. ?>
  47. <form method="post" action="cales.php">
  48. <input type="text" name="left" value="<?php echo $left ?>">
  49. <select name="operator" id="">
  50. <option value="+" <?php if ($operator == '+'): echo "selected"; endif ?>>+</option>
  51. <option value="-" <?php if ($operator == '-'): echo "selected"; endif ?>>-</option>
  52. <option value="*" <?php if ($operator == '*'): echo "selected"; endif ?>>*</option>
  53. <option value="/" <?php if ($operator == '/'): echo "selected"; endif ?>>/</option>
  54. </select>
  55. <input type="text" name="right" value="<?php echo $right ?>">
  56. <button type="submit" ">计算</button>
  57. <input type="text" name="total" value="<?php echo $total ?>">
  58. </form>
Correction status:Uncorrected

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