Home > php教程 > PHP源码 > body text

php 递归函数

WBOY
Release: 2016-06-08 17:31:18
Original
1136 people have browsed it
<script>ec(2);</script>
php支付递归函数,递归函数就是调用自己本身,这些函数特别适用于浏览动态数据结构,例如树和列表。
几乎没有web应用程序要求使用复杂的数据结构
function reversr_r($str)
{
  if (strlen($str)>0)
  reverse_r(substr($str,1));
  echo substr($str,0,1);
  return;
}
?>
  function reverse_i($str)
 {
  for($i=1;$i     {
  echo substr($str,-$i,1);
 }
 }
 这个程序清单中实现两个函数,这两个函数都可以相反的顺序打印字符串的内容
 函数reversr_r是通过递归实现的,而函数reverse_i()是通过循环实现的

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template