An array of PHP built-in methods

Source: Internet
Author: User
Tags sorts

This article introduces the contents of the PHP built-in method of the array, has a certain reference value, now share to everyone, the need for friends can refer to

Array Chapter


PHP 5 Array function

Function description

function Description
Array () Create an array
Array_change_key_case () Change all keys in an array to lowercase or uppercase
Array_chunk () Splits an array into a new array block
Array_column () Returns the value of a single column in the input array
Array_combine () Create a new array by merging two arrays
Array_count_values () Used to count the occurrences of all values in the array.
Array_diff () Compares an array and returns the difference set (only the key value is compared).
ARRAY_DIFF_ASSOC () Compares the array, returning the difference (comparing key names and key values).
Array_diff_key () Compares the array, returning the difference set (only the key name is compared).
ARRAY_DIFF_UASSOC () Compare arrays, return difference sets (compare key names and key values, use user-defined key-name comparison functions).
Array_diff_ukey () Compares the array, returns the difference set (only the key name is compared, using the user-defined key name comparison function).
Array_fill () Fills the array with the given key value.
Array_fill_keys () Populates an array with the given key value for the specified key name.
Array_filter () Filters the elements in the array with a callback function.
Array_flip () Swaps the keys and values in the array.
Array_intersect () Compares the array, returning the intersection (only the key values are compared).
ARRAY_INTERSECT_ASSOC () Compares an array, returning the intersection (comparing key names and key values).
Array_intersect_key () Compares the array, returning the intersection (only the key names are compared).
ARRAY_INTERSECT_UASSOC () Compares the array, returning the intersection (comparing key names and key values, using a user-defined key-name comparison function).
Array_intersect_ukey () Compares the array, returning the intersection (only the key names are compared, using the user-defined key-name comparison function).
Array_key_exists () Checks whether the specified key name exists in the array.
Array_keys () Returns all the key names in the array.
Array_map () Sends each value in the array to the user-defined function, returning the new value.
Array_merge () Merges one or more arrays into an array.
Array_merge_recursive () Merges one or more arrays recursively.
Array_multisort () Sorts multiple arrays or multidimensional arrays.
Array_pad () Fills the array with a value to the specified length.
Array_pop () Deletes the last element of the array (out of the stack).
Array_product () Computes the product of all the values in the array.
Array_push () Inserts one or more elements into the end of the array (into the stack).
Array_rand () Returns one or more random keys in the array.
Array_reduce () Returns an array as a string by using a user-defined function.
Array_replace () Replaces the value of the first array with the value of the subsequent array.
Array_replace_recursive () Recursively replaces the value of the first array with the value of the subsequent array.
Array_reverse () Returns the array in reverse order.
Array_search () Searches for the given value in the array and returns the key name.
Array_shift () Deletes the first element in the array and returns the value of the deleted element.
Array_slice () Returns the selected part of the array.
Array_splice () Deletes and replaces the specified element in the array.
Array_sum () Returns the and of the values in the array.
Array_udiff () Compares the array, returns the difference set (compares values only, uses a user-defined key-name comparison function).
ARRAY_UDIFF_ASSOC () Compare arrays, return difference sets (compare keys and values, compare key names using built-in functions, compare key values with user-defined functions).
ARRAY_UDIFF_UASSOC () Compare arrays, return the difference (compare keys and values, use two user-defined key-name comparison functions).
Array_uintersect () Compare arrays, return intersection (compare values only, use a user-defined key-name comparison function).
ARRAY_UINTERSECT_ASSOC () Compare arrays, return intersections (compare keys and values, compare key names using built-in functions, compare key values with user-defined functions).
ARRAY_UINTERSECT_UASSOC () Compare arrays, return intersection (compare keys and values, use two user-defined key-name comparison functions).
Array_unique () Deletes duplicate values in the array.
Array_unshift () Inserts one or more elements at the beginning of the array.
Array_values () Returns all the values in the array.
Array_walk () Applies a user function to each member in an array.
Array_walk_recursive () Each member of the array is recursively applied to the user function.
Arsort () Sorts the associative array in descending order of the key values.
Asort () Sorts the associative array in ascending order of key values.
Compact () Create an array that contains the variable names and their values.
Count () Returns the number of elements in the array.
Current () Returns the current element in the array.
each () Returns the current key/value pair in the array.
End () Points the inner pointer of the array to the last element.
Extract () Imports a variable from an array into the current symbol table.
In_array () Checks whether the specified value exists in the array.
Key () Gets the key name from the associative array.
Krsort () The array is reversed by key name.
Ksort () Arrays are sorted by key name.
List () Assigns the values in the array to some variables.
Natcasesort () Use the "natural sort" algorithm to sort the case-insensitive letters of an array.
Natsort () Use the "natural sort" algorithm to sort the array.
Next () Moves the inner pointer in the array forward one bit.
POS () The alias of current ().
Prev () Returns the internal pointer of the array back to one bit.
Range () Creates an array that contains the specified range of cells.
Reset () Points the inner pointer of the array to the first element.
Rsort () Reverse-order an array.
Shuffle () The array is scrambled.
sizeof () The alias of Count ().
Sort () Sorts the array.
Uasort () Use a user-defined comparison function to sort the key values in the array.
Uksort () Use a user-defined comparison function to sort the key names in the array.
Usort () Use a user-defined comparison function to sort the array.

Array_change_key_case ()

Converts all the keys of an array to uppercase letters:

$age =array ("Bill" and "the", "Steve" and "a", "Mark" = "+");p Rint_r (Array_change_key_case ($age, case_upper));

Definition and usage

    • The Array_change_key_case () function converts all keys in an array to uppercase or lowercase letters.
      The numeric index of the array does not change. If an optional parameter (that is, the second parameter) is not supplied, the default is converted to lowercase letters.

    • Note: If two or more keys are the same when you run the function, the last element overrides the other elements

Array_chunk ()

Splits the array into an array with two elements and preserves the key names in the original array:

$age =array ("Bill" = "All", "Steve" = "+", "Mark" = "+", "David" + "+");p Rint_r (Array_chunk ($age, 2,true) );
    • The third argument, which can be omitted, defaults to False (does not preserve the original key name and generates an indexed array)

Array_column ()

Remove the Last_Name column from the recordset and use the corresponding "id" column as the key value:

$a = Array (            ' id ' = = 5698,            ' first_name ' = ' Bill ', ' last_name ' = ' Gates ',        ),        Array ('            id ' = = 4767,            ' first_name ' = ' Steve ',            ' last_name ' = ' Jobs ',        )        Array (            ' id ' = ' = 3809,            ' first_name ' + ' Mark ', ' last_name ' = ' Zuckerberg ', ')    ; $last _names = array _column ($a, ' last_name ', ' id ');p rint_r ($last _names);//output Array (  [5698] = Gates  [4767] = Jobs  [ 3809] = Zuckerberg)
    • The third parameter is not filled in, returns an indexed array

Array_combine ()

A new array is created by merging two arrays, one of which is the key name and the other array element is the key value:

$key = Array ("Bill", "Steve", "Mark"), $value = Array ("", "" + "), $c =array_combine ($key, $value);//output Array (" Bill "= > ' A ', ' Steve ' and ' + ', ' Mark ' = ' 31 ');
    • Key an array group

    • Array of Value key values

Array_count_values ()

Count all the values in the array:

$a =array ("a", "Cat", "Dog", "a", "dog");p Rint_r (array_count_values ($a));
    • This function returns an array whose key name is the value of the original array, and the key value is the number of occurrences of the value in the original array.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.