each (array);
Role:
Returns the key and value for the current array, and moves the inner pointer forward.
Parameters:
Array: Arrays
return value:
Returns the current element
Example: use each to return each value of an array
$a = Array (' a ' = = ' red ', ' b ' = ' blue ', ' c ' = ' yellow '); while (list ($key, $value) = each ($a)) {echo "$key $value \ n";} Output: A->redb->bluec->yellow
End (array);
Role:
Point an internal pointer to the last element
Parameters:
Array: Arrays
return value:
Successfully returns the value of the last element, failure returns false
Example: The last parameter of an output array
$a = Array (' a ' = = ' red ', ' b ' = ' blue ', ' c ' = ' yellow '); $res = end ($a); Print_r ($res); Output Result: Yellow
Extract (array, extract_rules, prefix)
Role:
Use the array's key as the variable, and the value of the array as the variable
Parameters:
Array: Arrays
Extract_rules:
Optional. The extract () function checks to see if each key name is a valid variable name, and also checks to see if the variable name already exists in the symbol table conflicts. The handling of non-law and conflicting key names is determined by this parameter.
Possible values:
Extr_overwrite-Default. If there is a conflict, overwrite the existing variable.
Extr_skip-If there is a conflict, do not overwrite the existing variable.
Extr_prefix_same-If there is a conflict, precede the variable name with the prefix PREFIX.
Extr_prefix_all-Prefix all variable names with PREFIX.
Extr_prefix_invalid-Prefix PREFIX only before the illegal or numeric variable name.
Extr_if_exists-Overrides the value of a variable with the same name in the current symbol table only. None of the others will deal with it.
Extr_prefix_if_exists-A variable name with the prefix appended to it is created only if a variable with the same name already exists in the current symbol table, and none of the others are processed.
Extr_refs-Extracts the variable as a reference. The imported variable still references the value of the array parameter.
Prefix
Optional. Extr_prefix_if_exists is required if the value of the Extract_rules parameter is Extr_prefix_same, Extr_prefix_all, Extr_prefix_invalid, or PREFIX.
This parameter specifies the prefix. An underscore is automatically added between the prefix and the array key name.
return value:
Returns the number of variables that were set successfully.
Example:
1, the array key as the variable name $a = Array (' a ' = ' = ' red ', ' b ' = ' blue ', ' c ' = ' yellow '); $res = extract ($a); echo "$a \n$b\n$c\n"; Output: Red blue yellow 2, the array key as the variable name and add a prefix $a = array (' a ' = ' = ' red ', ' b ' = = ' blue ', ' c ' = ' yellow '); $res = Extract ($a, extr_prefix_all, ' my '); echo "$my _a\n$my_b\n$my_c\n"; Output result: Red Blue Yellow
In_array (value, array, strict);
Role:
Finds if value exists in array
Parameters:
Value: values that need to be looked up
Array: Arrays
Strict: optional, default feed false, if the True,value value needs to be the same as the type and value of the values in the array
return value:
Existence returns TRUE, Failure returns false
Example: whether the number 12 exists in an array
$a = Array (' a ' = = ' red ', ' b ' = ' blue ', ' c ' = ' 12 '); if (In_array ($a, true)) {echo ' exists ';} else {echo ' does not exist ';} Output result: not present
Key (array);
Role:
Gets the key for the internal pointer of the current array
Parameters:
Array: Arrays
return value:
Returns the key of the inner pointer in the array
Example:
$a = Array (' a ' = = ' red ', ' b ' = ' blue ', ' c ' = ' 12 '); $res = key ($a); Print_r ($res); Output Result: A
This article from "Snail Crawl" blog, please be sure to keep this source http://10130617.blog.51cto.com/10120617/1896276
PHP Learning Notes-Arrays (12)