Summarize the 10 most frequently used array functions in a project

Source: Internet
Author: User

Tag: Sum exit size indicates range repeat 16px tar optional parameter value

1,array_unique ($array)

Function: Remove duplicate values from the divisor group;

Parameter description: Generally only use the parameter value is to go to the heavy one-dimensional array;

Return value: The new array after the reset, preserving the original key name;

Note: The return value retains the key name of the first parameter in duplicate data by default ;

2,array_merge ($array, [$array],[$array] .... )

Function: Make an array or multiple arrays into a new array;

Parameter: at least one array;

Return value: Returns the new array;

Note: If two or more array elements have the same key name, the last element overrides the other element, and if there is only one and the key name is integer, the subscript starts at 0.

You can use this function to get a new key name to reorder by using the previous function to remove the weight.

3,Array_splice ($array, $start, [$length],[$array])

Function: Delete and replace the specified element in the array;

Parameters: The first is required array, the original array, the second is the beginning of the deletion or replacement, is required parameters, the third is an optional parameter, delete or replace the end of the position; the fourth is an optional parameter, the replacement of the new content;

Return value: Returns the content that was deleted or replaced;

Note: The second parameter can be a positive negative number, and a negative number is counted from the beginning of the end.

4,array_key_exits ($key, $array)

Function: Determine if there is a key name in the array;

Parameters: Two parameters are required, the first is the key name for the specified lookup, and the second is to find in an array, representing the range;

5,Array_search (value,array,strict)

Function: Find the specified key value and return the key name;

Parameters: The first and second parameters are required parameters, the specified lookup value and the specified array in which to find, the third parameter is optional parameter default is false;

Note: When the third parameter is specified as true, the key name of the corresponding element is returned only if the data type and value are identical ;

6,array_sum ($array)

Function: Calculates the sum of the values in the array;

Parameters: Arrays

return value: Sum (return integer by default)

Note: If a value is a floating-point number, the float is returned.

difference from count: sum is the sum calculated, and count is the number of calculations ;

7.In_array ($value, $array, $type)

Function: Finds whether the specified value exists in the array;

Parameters: Two is a required parameter. The first is the value to find, the second is a table-scoped array, the third is an optional parameter,

return value: boolean;

Note: If the third parameter is true, then the data of the lookup value is consistent with the type to match the success;

8.array_slice ($array, $start, $length, $type)

Function: Returns the specified data, similar to the interception of strings;

Parameters: The first second is required, respectively, the original array, specify the starting position of the return, the third fourth parameter is an optional parameter, respectively, the end position of the specified return, whether to retain the key name;

Return value: Returns the specified new array (silently resets the key name);

Note: The second third parameter can be negative, starting at the end; the fourth parameter defaults to False, and the reserved key name is true;

9,Array_pop ($array)

function: Delete last element

Parameters: Specifying an array of actions

Return value: Returns the deleted element

Note: null is returned if the array is empty or non-array

10.Array_push ($array, $value, [$value] ... )

Function: Add more than one element to the end of the array;

Parameters: Specify the added array and the value to add

Return value: New array

Note: The subscript of the newly added element starts at 0.

Summarize the 10 most frequently used array functions in a project

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.