PHP common function summary (array part) shared version may have some errors

Source: Internet
Author: User
Function name usage format input/output operation array generation and Conversion: array () generates an array arrayarray (mixed [...]) array value or, Key & gt; value an array variable without array_combine () generates an array, using the value of one array as the key name, and the other number... syntaxHighli

 

Function name usage format input/output operations

Array generation and conversion:

Array () generates an array (mixed [...]) value or, key => value: no

Array_combine () generates an array using the value of one array as the key name, and the value of another array as the value array array_combine (array $ keys, array $ values) $ keys is an array that provides keys, $ values: none of the arrays merged by the array that provides values

Range () creates an array range (mix $ low, mix $ high, [num $ step]) $ low minimum, $ high maximum, $ No array merged by step size

Compact () creates an array, including their variable names and values arr compact (mix $ varname, [, mix $...]) various variables and arrays return an array with the variable name as the key and the variable value as the value. The variable can also be a multi-dimensional array. will recursively process none

Array_fill () generates an array array_fill (int $ start, int $ num, mix $ value) $ start key with a given value, $ num elements, $ value indicates the completion of the returned array for the filled content.

Array merging and splitting:

Array_chuk () divides an array into multiple specified array array_chunk (arr $ input, int $ size [, bool $ preserve_keys]) $ input is an array operated, and $ size contains several elements each, $ preserve_keys Boolean type, whether to retain the multi-dimensional array after key segmentation

Array_merge () merges one or more arrays. if the key of the element is the same, the previous one will be overwritten, and the index sequence will not be overwritten. only arr array_merge (arr $ arr1 [, arr $ arr2,...]) will be automatically added. $ arr1: none of the arrays returned by the operated array

Array comparison operation:

Array_diff () calculates the array's difference set array array_diff (arr $ arr1, arr $ arr2 [,...]). input two or more arrays to compare the difference set of several array element values.

Array_intersect () calculates the intersection of arrays array array_intersect (arr $ arr1, arr $ arr2 [,...]) input two or more arrays to compare the intersection of several array element values.

 

Array search replacement operation:

Array_search () returns the specified value from the array with the name mix array_search (mix $ need, arr $ arr [bool $ stric]) $ need as the search string and $ arr as the target array, if $ stric is true, the return key name of the variable type must be matched. if the return key fails, false is returned.

Array_slice () extracts an arr array_slice (arr $ array, int $ offset [, int $ length [bool $ p_key]) from the array $ array target array; $ offset; $ length: specifies the truncation length. $ p_key: true indicates that the key name is retained. by default, the key name $ array target array is given again. if $ offset is not negative, the offset starts from this offset. if it is a negative value, the distance from the end starts. $ length is positive, there will be so many units in the sequence. if not negative, the sequence ends so far from the end. none

Array_splice () removes one part of the array and replaces arry array_splice with other values (arr & $ input, int $ offset [, int $ leng [, arr $ rep]). $ input is the target array, and $ offset is the offset. if $ leng does not exist, all elements from $ offset to the end are removed. if it is positive, so many units are removed, if the value is a negative value, the replacement of the original array is removed from the $ offk to the end of the $ leng, if $ rep is given, the original array will be replaced by the new array element.

Array_sum () calculates the sum of all values in the array and the number array_sum (arr $ array ).

In_array () is used to check whether a value exists in the array. case-sensitive bool in_array (mix $ need, arr $ array [, bool $ str]) is searched for $ need in $ array, if $ str is true, the check type also needs to match. if it is found, true is returned. if it is not found, false is returned.

Array_key_exists () checks whether the given key name has a bool array_key_exists (mix $ key, arr $ serch) $ key to find the key, $ serch the target array returns whether to find none

Array pointer operation:

Key ()

Current () alias pos ()

Next ()

Prev ()

End ()

Reset ()

List () assigns the values in the array to the variable void list (mix $ var1 [, $ var2. ..]) = arr $ array

Array_shift ()

Array_unshift ()

The array_push () array is finally pushed into multiple elements: int array_push (arr & $ array, mix $ var1 [, $ var2. ..]) & $ array target array, $ var1 .. if the input value is 1, the operation is successful. if the input value is 0, the operation is directly performed on the target array.

The final element mix array_pop () in the array_pop (arr & $ array)

Array key-value operation:

Shuffle () will disrupt the array, keep the key name bool shuffle (arr & $ array) input array, return true, disrupt the order, the key name will not change

Count ()

Array_flip () exchanges the keys and values in the array. arr array_flip (arr $ trans) $ trans is returned by the operation array.

Array_keys () returns all the keys of the array to form an array arr array_keys (arr $ input [, mix $ search [, bool $ str]). if $ search has a value, only the key name corresponding to this value is returned. if $ str is true, the array composed of the return key names must be compared.

Array_values () returns all values in the array to form an array array_values (array $ input)

Array_reverse () returns an array (arr array_reverse (arr $ input [, bool $ key]) with the opposite element order as the input target array, if $ key is true, no array with the opposite order of original key names is retained.

Array_count_values () counts the number of occurrences of all values in the array. array array_count_values (array $ input) $ input is the input value used as the key in the operated array, and the number of occurrences of the value does not exist in the array

Array_rand () randomly selects one or more elements from the array. Note the key name !!! Mix array_range (arr $ input [, int $ num]) $ input is the target array, and $ num is the key to extract several elements and return the extracted elements, if one key is used, it is a key name. if multiple elements are used, these keys are used as values to form an index array.

Each ()

Array_unique () removes duplicate values from the array, sorts the values first, then retains only the first key name encountered, and then ignores the remaining key names array array_unique (arr $ array) if the key name of the input target array remains unchanged, no repeated values are returned.

Sort arrays:

Sort () sorts arrays (from low to high) without retaining the key name bool sort (arr & $ array [, int $ flag]). The target array returns true, if an error is returned, the system returns false to rearrange the array elements and change the key name.

Rsort () sorts arrays in reverse order (from high to low) without retaining the key name bool rsort (arr & $ array [, int $ flag]). If the target array is successfully returned, true is returned, if an error is returned, the system returns false to rearrange the array elements and change the key name.

Asort () sorts arrays and maintains the index relationship bool asort (arr & $ array [, int $ flag]). If the target array is successfully returned, true is returned, and false is returned, retain the original index or key

Arsort () sorts arrays in reverse order to maintain the index relationship.

Ksort () sorts arrays by key names. Boolean ksort (arr & $ array [int $ flag]) returns true if the target array is successful, and false if the target array fails to be returned, reserve key-value mappings

Krsort () sorts arrays in reverse order by key name

Natsort () "natural algorithm" "sorts arrays and maintains the key-value relationship." bool natsort (arr & $ array) returns true if the target array is successfully returned, if the return value fails, the system returns false to sort the values and retains the key-value relationship.

Natcasesort () is naturally sorted. if the target array is not case sensitive, bool natcasesort (arr & $ array) returns true successfully. if the result is false, the value is not case sensitive, maintain key-value correspondence

 

From battlefield diaries _ LAMP brothers

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.