First, traverse
- Foreach
foreach (array_expression as $value) and foreach (array_expression as $key = = $value)
List () and each (): list () can only be used for arrays of numeric indexes, and the numeric index starts at 0. Each () returns the key names and corresponding values in the array, and moves the array pointer forward.
"PHP24 class", "1" and "JAVA24 Class", "2" and "VB24", "3" and "VC24 class"); while (List ($name, $value) =each ($array)) {// Use the list function to get the values of the returned array in each function, assign to $name and $value, and then use the while loop to output echo $name = $value. "
";//Output list function gets the key name and value}?>
Second, commonly used functions
Number of statistics array int count (mixed var)
Add an element to an array: Array_push () adds the passed-in element to the end of the array and returns the total number of new cells in the array
int Array_push (array array,mixed var)//array is the specified array, VAR is the value in the pressed array
Gets the last element in the array: Array_pop () returns the last element in the array, minus 1 of the array length, or null if the array is empty (or not an array). Mixed Array_pop (array array)
Delete duplicate elements in an array: array array_unique (array array)
Delete an element in an array: unset (mixed arr[*])
Gets the key name of the specified element in the array mixed Array_search (mixed Needle,array haystack[, bool Strict])//If the queried element appears more than two times in the array, the first matching key name is returned//needle: Specifies the value of the search in the array// Haystach: Specifies the array to be searched//strict: Optional parameter, if true, the type of needle is checked in haystack
array Array_keys (array input[, mixed search_value[, bool strict])// Returns all matching key names in the input array
Pre class= "Brush:php;toolbar:false" >
three, sort
sort () implements arrays from low to high, and strings are sorted in ASCII order.
BOOL Sort (array &array[, int sort_flags])//sort_flags specifies how to sort: sort_regular (default), Sort_numeric (compares elements as numbers), Sort_ String (compares the element as a string)
Rsort (): Used to sort the array from high to low.
The above describes the PHP array functions (traversal, sorting), including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.