Ange ($low, $high), Range ($low, $high, $step);//Create an array of sequential values such as range (1,4) (1,2,3,4) and range (' A ', ' Z ')
Each ($array) returns the current element of the array sequentially and sets the next element to the current element;
Reset ($array) to reset the current element of the array to the beginning of the array
List () can be used to decompose an array into a series of values, such as list ($a, $b) =each ($array)
Shuffle ($array), Array_rand ($arg, $num _req); random ordering of arrays
Array_reverse ($input), Array_reverse ($input, $preserve _keys) returns the reverse ordering of the original array
Sort ($array);
PHP array is an important concept, it contains a large number of functions to facilitate the development of people ... The array is categorized to facilitate query and application.
First, the definition of the PHP array ... PHP array contains two items, key and value, you can get the corresponding value by key, where key can be numeric and associated, such as $array[0], $array [one] ...
Create an array
The array declarations in PHP are a little bit different from other languages, but they can be declared as one-dimensional, two-D, three-dimensional and multidimensional, such as
$array [0] = 1, $array = Array (1,2,3); A one-dimensional array that contains only three values, is a numeric array, can be referenced with $array[0] to represent 1, and the index is omitted when you create an array of values.
Copy Code code as follows:
$array = Array (
1 => "One",
2 => "Two",
3 => "three",
4 => Array (
"One" => 1,
"Two" => 2,
"Three" => 3
)
);
Two-dimensional arrays, which are associative arrays, can be $array[4]["one" to represent 1 when referenced.
Three-dimensional above and so forth ...
If you want to create the array in bulk, you can use the following function:
Array range (mixed low, mixed high [, number step])
such as $array = Range (1,6), representing array (1,2,3,4,5,6);
$array = range (a,f); Representative Array (A,B,C,D,E,F);
Output array
There are more functions in the output array in PHP,
BOOL Print_r (mixed expression [, bool return])
void Var_dump (mixed expression [, mixed expression [, ...]])
And, like echo,print,printf, you can output a single array.
Test array
Sometimes we need to determine whether a variable is an array, and you can use:
BOOL Is_array (mixed Var)
Add or remove an array element
Array declarations are not immutable, and may be deeply manipulated by the addition of arrays:
int Array_push (array &array, mixed var [, mixed ...]) presses one or more cells into the end of the array, and the length of the array increases according to the number of the stack variables, such as Array_push ($array, $var)
Mixed Array_pop (array &array) pops the last element of the array (out of the stack) and resets the pointer to the array at the end
Mixed Array_shift (array &array) returns the first element of the array.
int Array_unshift (array &array, mixed var [, mixed ...]) inserts one or more cells at the beginning of the array
Array Array_pad (array input, int pad_size, mixed pad_value) fills arrays with values to a specified length, such as Array_pad ($array, 3, $var);
To locate an array element
BOOL In_array (mixed needle, array haystack [, BOOL strict]) checks whether a value exists in the array
Array Array_keys (array input [, mixed search_value [, BOOL Strict]]) returns all the key names in the array, and then makes up a new array
BOOL Array_key_exists (mixed key, array search) checks whether the given key exists in the array.
Array array_values (array input) returns all the values in the array
Mixed Array_search (mixed needle, array haystack [, bool strict]) searches the array for a given value, and succeeds in returning the key.
Traversing an array
PHP provides a lot of functions to get key and value
Mixed key (array &array) gets the key name from the associative array
Mixed reset (array &array) resets the array pointer
Array each (array &array) returns the key/value pairs in the array and moves the array one step forward
Mixed current (array &array) returns the active cell in the array
Mixed end (array &array) moves the pointer in the array to the last
Mixed next (array &array) moves the pointer in the array down one
Mixed prev (array &array) moves the pointer in an array up one
Array array_reverse (array array [, BOOL Preserve_keys]) returns a sequence of cells in reverse order
The array array_flip (array trans) swaps the key value roles in the array
In addition to the functions above, you can use loops to iterate through the elements of an array, such as
foreach (array_expr as $value)
{statement}
foreach (array_expr as $key => $value)
{statement}
Extracts each key/value pair until all items are obtained or some internal conditions are met
void list (mixed varname, mixed ...) assigns the values in the array to some variables
Determining the size and uniqueness of an array
int count (mixed var [, int mode]) computes the number of attributes in a cell array or object in an array, sizeof a function of the same name
Array array_count_values (array input) counts the number of occurrences of all values in an array
Array array_unique (array array) to move the duplicate values in the divisor group
Array sorting
This hearing is the core of the calculator ... Oh... That's the way it is.
BOOL Sort (array &array [, int sort_flags]) sorts by array
BOOL Natsort (array &array) sorted by natural sorting method in pairs
the bool Natcasesort (array &array) is sorted by natural sorting by array, case-insensitive
BOOL Rsort (array &array [, int sort_flags]) to reverse-sort the array
BOOL Asort (array &array [, int sort_flags]) sorts and maintains index relationships for arrays
BOOL Array_multisort (array ar1 [, mixed arg [, mixed ... [, array ...]] To sort multiple arrays or multidimensional arrays
BOOL Arsort (array &array [, int sort_flags]) sorts the array in reverse order and maintains an indexed relationship
BOOL Ksort (array &array [, int sort_flags]) sort of array key names
BOOL Krsort (array &array [, int sort_flags]) reverse order of array key names
Merging, splitting, joining, and decomposing arrays
Array array_combine (array keys, array values) creates an array with the value of one array as its key name and the value of the other array as its value
Array Array_merge (array array1 [, array array2 [, array ...]]) merges one or more arrays
Array array_merge_recursive (array array1 [, array ...]) recursively all one or more arrays
Array array_slice (array array, int offset [, int length [, bool Preserve_keys]]) takes a paragraph from an array, creates a new array, and, if offset is a positive number, splits the array switch from the distance Offset position, if negative, the split starts at the offset position from the end of the array, at which point the count (Input_array)-|length| from the array switch ends
Array Array_splice (array &input, int offset [, int length [, array replacement]]) removes some of the values in the array and replaces them with other values. Offset Settings ditto
Array Array_intersect (array array1, array array2 [, array ...]) computes the intersection of the array, which means that if the value that appears in the first array appears in the next few arrays, the value is fetched
Array Array_intersect_assoc (array array1, array array2 [, array ...]) checking the intersection in an array with an index
Array Array_intersect_key (array array1, array array2 [, array ...]) to compare the intersection in an array by using a key name
The array array_diff (array array1, array array2 [, array ...]) computes the difference set of arrays, that is, the different values in the first array
Array Array_diff_assoc (array array1, array array2 [, array ...]) Check the difference set in an array with an index
Array Array_diff_key (array array1, array array2 [, array ...]) to compare the difference set in an array by using a key name
Other, more useful array functions
There are a lot of array functions that are not listed ... A few more useful and more often, the other on the reference manual ... It's clear in the handbook.
Mixed Array_rand (array input [, int num_req]) An array of randomly fetched one or more keys, num specified number
BOOL Shuffle (array &array) disrupts arrays
Number Array_sum (array array) evaluates the sum of all the values in the array, and the associative array ignores
Array array_chunk (array input, int size [, bool Preserve_keys]) divides an array into several