1. Array definitions
defined in different ways
You can put any type of data inside the array.
1). Indexed array
$attr Array ("AA");
Print_r ($ATTR);
2). Associative arrays
$attr Array ("One" =>10, "one" and "a" = "AA", "three" =>20); // Key=>value Print_r ($attr); Echo $attr // associative arrays can only be taken with key
2. Iterating through an array
For loop traversal, can only traverse indexed array, cannot traverse associative array
$attr Array ("AA"); for ($i$i<count($attr); $i+ +) {echo$attr[$i];}
foreach traversal, which can traverse associative arrays and indexed arrays
// traversing values only foreach ($attr as$value) {echo$value;} // traversing keys and values for ($attras$key= +$value) {echo$key ." = ". $value ;}
each () function list () function
//each () function, go to an element inside the array, take the value down, and return the element as an array$attr=Array("One" =>10, "2" = "AA", "three" =>20);Print_r( each($attr));Print_r( each($attr));Print_r( each($attr));Echo"------------------------"Reset($attr);//pointer Reset, pointing to the first element
// list () function $attr = array (1,2,3,4, "AA" ); list ( $a , $b , $c ) = $attr echo $a echo $b echo $c list (,,,, $f ) = $attr
// each () and list () iterates through an array, indexed arrays and associative arrays can be $attrArray ("One" =>10, "2" = "AA", "three" = >20); while (list($key,$value) =each(attr)) { echo$key ." = ". $value. " <br> ";}
3. Pointers
Current($attr);//takes the current pointer to the contents of the valueKey($ATTT);//index key to which the current pointer is pointingNext($attr);//move the pointer downprev($attr);//move the pointer upEnd($attr);//point pointer to last elementReset($attr); Reset the pointer//Traverse Do{Echo Key($attr);Echo Current($attr);Echo"<br>";} while(Next($attr))
4. Pre-defined arrays
$_server Server and execution Environment information $_get$_post$_request$_files$_cookie $_session
PHP Language--arrays