Home > Backend Development > PHP Tutorial > A brief discussion on the classification principle of PHP Infinitus

A brief discussion on the classification principle of PHP Infinitus

little bottle
Release: 2023-04-06 10:38:02
forward
2820 people have browsed it

This article mainly talks about the principles of PHP Infinitus classification. It has certain learning value. Interested friends can learn about it and hope to help you answer your doubts.

1. Recursion: The programming technique in which a program calls itself is called recursion

2. Case:

/**
 * @param 递归 $[name] 
 */
function deeploop(&$i=1){
    echo $i;
    $i++;
    if($i < 10){
        deeploop($i);
    }
}
deeploop();
结果:123456789
Copy after login

3.global

/**
 * @param 递归 $[name] 
 */
$i = 1;
function deeploop(){
    global $i; //Global的作用是定义全局变量,但是这个全局变量不是应用于整个网站,而是应用于当前页面,包括include或require的所有文件。
    echo $i;
    $i++;
    if($i < 10){
        deeploop($i);
    }
}
deeploop();
Copy after login

4.static

/**
 * @param 递归 $[name] 
 */
function deeploop(){
    static $i; 
    echo $i;
    $i++;
    if($i < 10){
        deeploop($i);
    }
}
deeploop();
Copy after login

5. To put it bluntly, recursion is a loop. The effect of loop implementation and recursive implementation is the same.

<span style="color: #000000;">/**
 * @param 递归 $[name] 
 */
for($i=1;$i</span><span style="color: #0000ff;"><</span><span style="color: #800000;">10</span><span style="color: #ff0000;">;$i++){
    echo $i;
}
function deeploop(){
    static $i; 
    echo $i;
    $i++;
    if($i < 10){
        deeploop($i);
    }
}
deeploop();<br/>结果:<br/>1233456789<br/>123456789<br/></span>
Copy after login

##Related tutorials:

PHP video tutorial

The above is the detailed content of A brief discussion on the classification principle of PHP Infinitus. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template