Summary of PHP functions

Source: Internet
Author: User
Tags array sort compact shuffle

The key name and value of the array

Array_values ($arr); Get the value of an array

Array_keys ($arr); Gets the key name of the array

Array_flip ($arr); the values in the array are interchanged with the health name (if there are duplicates, the previous one will be overwritten by the following)

In_array (' Apple ', $arr); Retrieve Apple in an array

Array_search (' Apple ', $arr); Retrieve Apple in an array if there is a return health name

Array_key_exists (' Apple ', $arr); Retrieves whether the given health name exists in the array

Isset ($arr [Apple]); Retrieves whether the given health name exists in the array

An internal pointer to an array

Current ($arr); Returns the cell in the array

POS ($arr); Returns the current cell in the array

Key ($arr); Returns the health name of the current cell in the array

Prev ($arr); Rewind the internal pointer in the array back to a

Next ($arr); Moves the inner pointer in the array forward by one

End ($arr); point the inner pointer in the array to the last cell

Reset ($arr); point the inner pointer in the array to the first cell

each ($arr); Constructs an array of one health name/value of the current element of the array and moves the array pointer forward one

List ($key, $value) =each ($arr); Gets the health name and value of the current element of the array

Conversions before arrays and variables

Extract ($arr); used to convert elements in an array into variables into the current file, the health name as the variable name, the value as the value of the variable

Compact (VAR1,VAR2,VAR3); Create an array with the given variable name

Ii. segmentation and padding of arrays

Fragment of an array

Array_slice ($arr, 0, 3); You can take a paragraph out of the array, which ignores the health name

Array_splice ($arr, 0,3,array (' Black ', ' maroom ')); You can take a paragraph out of an array, unlike the previous function, in which the returned sequence is removed from the original array.

Splitting multiple arrays

Array_chunk ($arr, 3,true); You can split an array into multiple, TRUE to preserve the name of the original array

Padding of arrays

Array_pad ($arr, 5, ' X '); fills an array to a specified length

Three, arrays and buyers

Array_push ($arr, ' apple ', ' pear '); press one or more elements into the end of the array buyers (in buyers), returning the number of elements in the buyers

Array_pop ($arr); POPs the last element of the array buyers (out of buyers)

Iv. Arrays and queues

Array_shift ($arr); The first element in the array is returned as a result (the array length minus 1, the other elements move forward one bit, the number is changed from zero to count, the word Health name unchanged)

Array_unshift ($arr, ' a ', array); inserts one or more elements at the beginning of the array

Five back-tone function

Array_walk ($arr, ' function ', ' words '); Each member of an array that uses the user function is processed (the third argument is passed to the callback function)

Array_mpa (' function ', $arr 1, $arr 2); You can work with multiple arrays (they should be the same length when using two or more sets of numbers)

Array_fiter ($arr, "function"), using a callback function to filter each element in the array, if the callback function is true, the current element of the array is included in the returned result array, and the health name of the array remains unchanged

Array_reduce ($arr, ' function ', ' * '); Convert to a single-valued function (* The first value of an array)

Vi. Ordering of arrays

Sort by array of element values

Sort ($arr), sorted by order of small to large (the second argument is sorted by what sort) ignores the array sort of a health name

Rsort ($arr); Sort by order of large to small (the second argument is sorted in any way) ignores the array sort of a health name

Usort ($arr, ' function '); Use a user-defined comparison function to sort the values in the array (there are two parameters in function, 0 for equality, positive for the first is greater than the second, negative for the first less than the second) to sort the arrays that ignore the name of a health

Asort ($arr); Sort by order of small to large (the second argument is sorted by what way) to preserve the array ordering of the health name

Arsort ($arr); Sort by order of large to small (the second argument is sorted by what sort) preserve the array of health names

Uasort ($arr, ' function '); Sorts the values in the array using a user-defined comparison function (two parameters in function, 0 for equality, positive for the first greater than the second, negative for the first one less than the second) to sort the array preserving the health name

Sort by the name of a health group

Ksort ($arr), sorted by healthy name

Krsort ($arr); Sort by name in reverse order

Uksort ($arr, ' function '); Use a user-defined comparison function to sort the health names in the array (there are two parameters in function, 0 for equality, positive for the first greater than the second, and negative for the first less than the second one)

Sort by natural sort

Natsort ($arr); natural sort (ignore health name)

Natcasesort ($arr); natural sort (ignoring case, ignoring health name)

Vii. Calculation of arrays

Sum of array elements

Array_sum ($arr); sums all elements inside an array

Merging of arrays

Array_merge ($arr 1, $arr 2); merges two or more arrays (the same string health name, followed by the same number with the previous, the same numeric health name, followed by no overwrite operation, but appended to the back)

"+" $arr 1+ $arr 2; For the same health name, keep only the latter one

Array_merge_recursive ($arr 1, $arr 2); Recursive merge operations, if the array has the same string health name, the values will be merged into an array. If a value is itself an array, it will be merged into another array according to the corresponding health name. When the array has the same array health name, the latter value will not overwrite the original large value, but append to the back

The difference set of an array

Array_diff ($arr 1, $arr 2); Returns an array of difference results

ARRAY_DIFF_ASSOC ($arr 1, $arr 2, $arr 3); Returns the array of difference results, and the health name is also compared

Intersection of arrays

Array_intersect ($arr 1, $arr 2); Returns an array of intersection results

Array_unique ($arr); Removes duplicate values from the array, preserving the original health name in the new arrays

Array_reverse ($arr, True); Returns an array whose cell order is the opposite of the original array, if the second argument is true to preserve the original health name

Array_rand ($arr, 2); Randomly fetching one or more elements from an array

Shuffle ($arr); disturb the order of the array

This class of functions allows you to manipulate arrays and interact with them in a variety of ways. The essence of an array is to store, manage, and manipulate a set of variables.

PHP supports one-dimensional and multidimensional arrays, either created by the user or created by another function, and there are specific array library handlers that can generate arrays from database queries, and some functions return arrays.

Array_change_key_case returns an array of string health names that are all lowercase or uppercase

Array_chunk splits an array into multiple

Array_combine creates an array with the value of an array as its health name, and the value of another array as its value

Array_count_values the number of occurrences of all values in the statistics array

ARRAY_DIFF_ASSOC with index Check the difference set of the computed array

Array_diff_key using a health name to compare the difference set of an array

Array_diff_uassoc using the user-supplied callback function to do index checking to calculate the difference set of the array

Array_diff_ukey comparing the difference set of an array with a callback function to a health name

Array_diff Calculating the difference set of an array

Array_fill_keys

Array_fill fills an array with the given value

Array_filter filter cells in an array with callback functions

Array_flip exchanging keys and values in an array

ARRAY_INTERSECT_ASSOC with index Check the intersection of computed arrays

ARRAY_INTERSECT_UASSOC with index Check the intersection of computed arrays, using callback function to compare indexes

Array_intersect _ukey computes the intersection of an array using a callback function to compare a health name

Array_intersect computes the intersection of an array

Array_key_exists checks if the given health name or index exists in the array

Array_keys returns all the health names in the array

Array_map the callback function to the cell of the given array

Array_merge_recursive merge one or more arrays recursively

Array_merge merging one or more arrays

Array_multisort to sort multiple arrays or multidimensional arrays

Array_pad fills an array to a specified length with a value

Array_pop pops the last cell of the array (out of buyers)

Array_product computes the product of all values in an array

Array_push pressing one or more cells into the end of the array (into buyers)

Array_rand random or multiple cells out of an array

Array_reduce to simplify the array to a single value using the callback function iteration

Array_reverse returns an array of cells in reverse order

Array_search searches the array for the given value and returns the corresponding health name if successful

Array_shift the cells at the beginning of the array by dividing the group

Array_slice remove a paragraph from an array

Array_splice to remove part of an array and replace it with other values

Array_sum computes the and of all values in the array

ARRAY_UDIFF_ASSOC with index Check the difference set of the computed array, using the callback function to compare the data

ARRAY_UDIFF_UASSOC with index Check to calculate the difference of the array, compare the data and index with the callback function

Array_udiff comparing data with callback functions to calculate the difference set of an array

ARRAY_UITERSECT_ASSOC with index Check the intersection of the computed array, using the callback function to compare the data

ARRAY_UITERSET_UASSOC with index Check the intersection of computed arrays, using callback functions to compare data and indexes

Array_uitersect computes the intersection of an array, compares the data with a callback function

Array_unique duplicate values in an array

Array_unshift inserting one or more cells at the beginning of an array

Array_values returns all values in the array

Array_walk_recursive Application user function recursively for each member in an array

Array_walk applying user functions to each member in an array

Array to create a new arrays

Arsort an array in reverse order and maintain an index relationship

Asort sorting an array and maintaining an index relationship

Compact establishes an array, including the variable names and their values

Count counts the number of cells in an array or the number of properties in an object

Current returns the cell in the array

Each returns the current key/value pair in the array and moves the array pointer forward one step

End points The inner pointer of the array to the last cell

Extract importing variables from an array into the current symbol table

In_array checks if a value exists in the array

Key gets the health name from the associative array

Krsort an array in reverse order by health name

Ksort array sorted by health name

List assigns the values in the array to some variables

Natcasesort sorting of case-insensitive letters using natural sorting algorithm for arrays

Natsort sorting with natural sorting algorithm for arrays

Next moves the inner pointer in the array forward by one

Alias for Pos curent ()

Prev The internal pointer of the array back to a

Range to create an array containing the specified range of cells

Reset points The inner pointer of the array to the first cell

Shuffle array is scrambled

The alias of sizeof Count ()

Sort array Sorting

Uasort use a user-defined comparison function to sort the values in the array and keep the index associated

Uksort using a user-defined comparison function to sort the health names in the array

Usort using a user-defined comparison function to sort values in an array

Summary of PHP functions

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.