dongshi3361 2013-09-24 21:41
浏览 28
已采纳

扩展PHP:超文本处理器[关闭]

I am learning recursion now in my programming class, and while I understand how to use recursion for things like factorials and backtracking algorithms, I've been trying to wrap my head around how a recursive acronym, such as PHP, would be iterated for quite some time know. How could one write a program to iterate the expansion of PHP n times?

EDIT: I need to clarify my question PHP is a recursive acronym, stands for PHP: Personal home page. So if you were to expand PHP: Hypertext processor an infinite number of times, would it look like PHP:Hypertext Processor Hypertext processor hypertext processor... or soemthing different

  • 写回答

3条回答 默认 最新

  • duanfei8897 2013-09-24 21:48
    关注

    I am completely guessing as to what you're asking, but if I'm right it would be something like this:

    function recursePHP($n) {
        if ($n <= 0)
            return 'PHP';
    
        return recursePHP($n-1) . 'Hypertext Processor';
    }
    

    This is taking a recursive function approach to your question that would spit out, given n=2: "PHP Hypertext Processor Hypertext Processor"

    I see this as the correct way to recurse through the acronym, as thinking about the first iteration you end up with "PHP Hypertext Processor", the PHP in this resolves to "PHP Hypertext Processor" so that becomes "PHP Hypertext Processor Hypertext Processor" with the bold section being the PHP in the first iteration, etc. Until you've iterated through the specified number of recursions then you don't resolve PHP and end up with PHP at the beginning followed by n "Hypertext Processor"s.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测