We don't have a lot of PHP information on hand, we have a php4gb.chm. I most appreciate the library part of it, the real online help. But the pace of PHP development is so fast, you sui, I recently found some extended array functions in www.php.net/manual/.
Below I introduce them to everybody, my English level is not high, has the translation wrong place, please correct me.
The format is this:
Function name Support version
function declaration
Description and parameters, return value
Array array_count_values (array input)
Counts the number of values in the input array. Returns an array with the value of input as the key to the new array with the number value.
Array Array_merge (array array1, array array2 [, array ...])
Merges multiple arrays, adding the contents of the array2 to the back of the array1. Returns an array of results.
If it is an associative array, with a string as key, and a key with the same name appears, the following will overwrite the previous one, and the subscript array will not appear overwritten, just add it to the back.
Array array_merge_recursive (array array1, array array2 [, array ...])
Recursively merges an array, essentially similar to the previous function. The difference is that in the associative array, it is not simply merging the same key or generating a two-dimensional array to merge the value of the same key. (The expression is not clear, sorry, see examples).
Array Array_intersect (array array1, array array2 [, array ...])
Takes the intersection of multiple arrays and returns a new array that contains the elements of the intersection.
Based on array1, so, if it's an associative array, the key value is array1. See examples.
The two functions are related and put together.
Array_keys can take out all the keys of an array, and if search_value is defined, only the corresponding key value is taken.
Array_values takes out all value values for array input.
Sort multiple arrays at the same time, or multiple dimensions for a multidimensional array. (Very useful, my last time in Chinese users asked this question).
The input array is processed into a table column, sorted by row, somewhat analogous to an order by condition in an SQL statement.
The parameters of this function are not common, but they are flexible. But an array or some of the following flags.
SORT_ASC-Ascending
Sort_desc-Descending
Sort_regular-General comparison
Sort_numeric-Numerical comparison
Sort_string-string comparison
An array cannot be given two types of sort flags at the same time (this is of course). The flag after each array is valid only for this array. The default is SORT_ASC and Sort_regular.
After sorting, the "I" Contain, "a" (it is sorted as strings in ascending order), and the SE Cond one would contain 1, 3, "2", 1 (sorted as numbers, in descending order).
However, the above example I tried, no, will report parameter 3 is an array of errors. (??? I don't even have one.
If you use Array_multisort directly ($ar [0],SORT_ASC, $ar [1],sort_desc];
Mixed Array_pop (array array)
int Array_push (array array, mixed var [, mixed ...])
Mixed Array_shift (array array)
int Array_unshift (array array, mixed var [, mixed ...])
The array is used as a function of the stack. The use of the concrete is relatively simple:
POPs pops up the last element and returns the element value.
Push adds the parameter var to the array at the end. return position. Same as $array[]= $var function. Returns the number of new elements in the array.
Shift to eject the first element of the array, and the other to move one position, equivalent to the left offset. But the number of array elements is reduced by 1. Returns the element that pops up.
Unshift adds one or more elements to the array before returning the number of new arrays.
Example 1. Array_pop () example
$stack = Array ("Orange", "apple", "raspberry");
$fruit = Array_pop ($stack);
After this, the $stack has only 2 elements: "Orange" and "Apple", and $fruit has "raspberry".
Example 2. Array_push () example
$stack = Array (1, 2);
Array_push ($stack, "+", 3);
This example would result in $stack has 4 elements:1, 2, "+", and 3.
Example 3. Array_shift () example
$args = Array ("-V", "-f");
$opt = Array_shift ($args);
This would result in $args has one element, "-F" left, and $opt being "-V".
Example 4. Array_unshift () example
$queue = Array ("P1", "P3");
Array_unshift ($queue, "P4", "P5", "P6");
This would result in $queue has 5 elements: "P4", "P5", "P6", "P1", and "P3".
Randomly select one or more elements from an array. The parameter num_req gives the number of elements to be selected, the default is 1.
Returns an array that contains the key of the selected element.
First call Srand () to produce random number of seeds.
Array array_reverse (array input)
Returns a new array that takes the elements of input in reverse order.
Example 1. Array_reverse () example
$input = Array ("PHP", 4.0, Array ("Green", "red"));
$result = Array_reverse ($input);
This makes $result have array (array ("Green", "Red"), 4.0, "PHP").
//****************************************
Array_slice (PHP4)
Array array_slice (array array, int offset [, int length])
Takes a portion of an array, starting at offset, length, and default to end.
Returns a new array.
Offset is positive, starting at the offset position of the array, if negative, counting from the end of the array.
Length is positive, is a new array of lengths, is negative, is also from the end of the array reciprocal.
Array array_splice (array input, int offset [, int length [, array replacement]])
Removes the part from the array that begins with offset and length, and replaces the removed part with this parameter if the replacement[] argument is given.
The processing judgment for offset and length is the same as the previous example.
If there is a replacement parameter, this parameter is used instead of the remove part, and if it is not removed, it is inserted at the offset position.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.