dsn46282 2017-12-13 16:30
浏览 77
已采纳

PHP:如何在不使用for / while循环的情况下连续打印文本

Without using a for/while loop or any kind of string repeat function and a single PHP file, print out the text “All work and no play makes jack a dull boy” to the screen 200 times in a list – Grade C: 15 lines of code – Grade B: 10 lines of code – Grade A: 7 lines of code – Grade A*: 4 lines of code (VERY difficult)

– n.b. a “line” counts as a statement. Each closing brace must go on its own line, function calls on their own line and function declarations on their own line. PHP tags

  • 写回答

1条回答 默认 最新

  • doudun1934 2017-12-13 16:38
    关注

    You can use php's array_fill() method to fill an array 200 times with your data. http://php.net/manual/en/function.array-fill.php

    After that you can use implode() to print that information out to the screen without using a loop. Show array without index key

    Of course, both of these methods will utilize a loop internally, but your code will be free of these.

    This should work:

    $a = array_fill(0, 200, 'banana');
    echo implode($a, '<br />');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建