Original article from (www.ympfb.com/show-29-121…

Pseudo type:

Mixed, indicating that a parameter can accept many different types. Number, indicating that an argument can be an integer or a floating point. Callback, indicating that the argument is a callback function. Void, if used as a return type, means that the return value of the function is useless. Being in a parameter list means that no parameters are accepted

Array traversal means to process each element in an array one by one.

Methods a foreach

1 <? php 2 3 $arr = ['a', 'b', 'c', 'd']; 4 5 foreach( $arr as $k => $v ){ 6 .... 7} 8 9 /* 10 $arr is the array to iterate over 11 take out each element of the array and assign it to $k 12 Assign the element value to $v 13 14 In other words, $k and $v are equivalent to the parameters 15 */ 16 17? >Copy the code

Way 2 for

1 <? php 2 3 $arr = ['a', 'b', 'c', 'd']; 4 $n = count( $arr ); 5 6 for($i = 0; $i < $n; $i++){ 7 echo $arr[ $i ]; 8} 9 10 /* 11 array subscript, must be consecutive index array 12 */ 13 14? >Copy the code

Reset () sets the pointer inside the array to the first cell

Next () moves the internal pointer in the array forward one bit

Prev () rewinds the internal pointer in the array by one bit

End () points the inner pointer to the last cell in the array

Current () returns the value of the current position of the pointer

Key () returns the index of the current position of the pointer

 1
<?php
2
    
3
    $arr = ['a', 'b', 'c', 'd'];
4
​
5
    reset($arr);
6
​
7
    while($v = current( $arr )){
8
        ....
9
        next($arr);
10
    }
11
​
12
?>
Copy the code

Way four list… each

1 <? php 2 3 $arr = ['a', 'b', 'c', 'd']; 4 5 while( list($k, $v) = each($arr) ){ 6 7 echo $k.'----'.$v; 8 9} 10 11 / * 12 each one element (array) every time out, returns an array of 13 list ($k $v) the contents of 14 to 0 the subscript assigned to $15 for the subscript 1 k content assigned to $16 17 18 * / v? >Copy the code