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

A brief discussion on the classification principle of PHP Infinitus

little bottle
little bottleforward
2019-04-24 17:52:272738browse

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

3.global

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

4.static

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

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>

##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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete