"聖經"遞迴有關問題的困惑 想了一天555也無解.

來源:互聯網
上載者:User
"聖經"遞迴問題的困惑 想了一天555也無解...
本帖最後由 iamsai 於 2013-09-24 21:00:08 編輯


$str='hello';
reverse_i($str);
function reverse_i($str)
{
if(strlen($str)>0)
{
reverse_i(substr($str,1));

}

echo substr($str,0,1);
return;

}
?>


請大家看我的問題:
此程式的輸出結果是倒序輸出 olleh .
經過迴圈體中reverse_i(substr($str,1));語句的操作 hello ello llo lo o
當字元長度==0時,echo substr($str,0,1); 輸出o.
return語句返回什麼值呢?是返回到第四行?後面的執行順序是什麼呢?有誰能幫我分析分析?謝謝大俠了!

分享到:


------解決方案--------------------
if(strlen($str)>0)
??{???
????reverse_i(substr($str,1)); //這是一次遞迴調用
<--- 返回到這裡
??}
??echo?substr($str,0,1);
??return;
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.