博客
关于我
php教程--案例5(金字塔)
阅读量:308 次
发布时间:2019-03-03

本文共 578 字,大约阅读时间需要 1 分钟。

"; // 空格部分 $empty_pos = 1; while ($empty_pos <= $empty) { echo " "; $empty_pos++; } // 星星部分 $star_pos = 1; while ($star_pos <= $star) { echo "*"; $star_pos++; } echo ""; $line++;}echo "

 

以上代码实现了一个动态生成金字塔效果的网页表格,具体流程如下:

  • 定义变量:$line表示当前行数,$empty表示当前行的空格数,$star表示当前行的星星数,$total_line表示总行数。

  • 循环从第1行到第$total_line行逐行生成:

    • 先输出空格部分:根据当前行数计算空格数,逐个输出空格。
    • 再输出星星部分:根据当前行数计算星星数,逐个输出星星。
    • 最后输出换行符,进入下一行循环。
  • 使用

    标签包裹表格,使用<tr标签表示表格行,
    标签表示表格单元格。

    特点:

    • 自动生成对称结构的金字塔
    • 行数可配置($total_line)
    • 自动生成适配的空格和星星数量
    • 代码简洁易懂
    • 性能较高(无复杂DOM操作)
    • 适合动态生成网页内容
  • 转载地址:http://apem.baihongyu.com/

    你可能感兴趣的文章
    python | six,一个神奇的 Python 库!
    查看>>
    Python读取图片的几种方法供net使用
    查看>>
    python | spacy,一个神奇的 Python 库!
    查看>>
    python | sqlmap,一个实用的 Python 库!
    查看>>
    python | sumy,一个超酷的 用于文本摘要的 Python 库!
    查看>>
    python | tiler,一个不可思议的 图像切片重组 Python 库!
    查看>>
    python | tinydb,一个非常厉害的 关于数据库的 Python 库!
    查看>>
    python | tox,一个超强的 自动化测试工具 Python 库!
    查看>>
    python | ttkbootstrap,一个神奇的 Python 库!
    查看>>
    python | unoconv,一个超厉害的 Python 库!
    查看>>
    python | urllib3,一个超强的 Python 库!
    查看>>
    python | webassets,一个超强的 Python 库!
    查看>>
    python | werkzeug,一个不可思议的 Python 库!
    查看>>
    python | xlsxwriter,一个实用的 Python 库!
    查看>>
    python | xlwings,一个非常实用的 Excel 相关的 Python 库!
    查看>>
    python | xmltodict,一个非常厉害的 关于XML数据 Python 库!
    查看>>
    python | xonsh,一个超酷的 Python 库!
    查看>>
    python | yagmail,一个实用的 Python 库!
    查看>>
    python | 一文掌握Python的上下文管理器和with语句
    查看>>
    python | 一文看懂Python闭包机制与变量作用域规则
    查看>>