php1.9--Array

Source: Internet
Author: User

The 1.array_slice () function is to take a value out of a condition in the array and return it, if the array has a string key, the returned array will retain the health name

Array array_slice (array array, int offset [, int length [, bool] preserve_keys])

The first parameter is required, and the second parameter that invokes the input to be processed is also required, a value that specifies the starting position of the removed element if it is a positive number, and then starts from the previous

If it is a negative number, from the back forward to offset the absolute value of the third parameter, the descendant of a value, the length of the returned array, if negative from the back forward, select the value of the absolute numbers of elements

If not set, returns all elements fourth parameter Optional Boolean type, if True returns array reserved key name default value false reset default key value

Example:

$arraylamp =array ("Linx", "Apache", "MySQL", "PHP");

Take 2 elements from the second start

Print_r (Array_slice ($arraylamp,));

Take an element from the back of the second

Print_r (array) slice ($arraylamp, -2,1));

The 2.array_splice () function is to select a series of elements in an array, but not to return, but to delete and replace them with other alternatives if the fourth argument is provided, then the elements previously selected will be fourth

parameter specifies the array to replace, and the last generated array returns

Array Array_splice (array $array, int offset [, int length [, array replacement]])

The first parameter must, the specified processing array, the second parameter offset is also the must, the descendant array, offset is a positive number, then from the input array of the value specified by the offset, if offset

is negative, the third parameter is removed from the offset specified by the value at the end of the input array, and a numeric value is removed, and if this argument is omitted, all values from offset to end in the divisor group are moved.

If length is positive, remove so many elements, negative, remove offset to the end of the array at the bottom of the length of the fourth parameter is optional, the element being removed from this array

Element overrides, if no value is removed, the elements in the number group are inserted at the specified position.

Example:

$input =array ("Linux", "Apache", "MySQL", "PHP");

Array_splice ($input, 2)//delete all elements after the second element

Print_r ($input);

All elements in the middle of the first position from the start of the second element

Array_splice ($input, 1,-1);

The last element is replaced by a fourth parameter value

Array_splice ($input, -1,1,array ("Web", "www"));

The 3.array_combine () function is to create a new array by merging two arrays, one of which is the key name and the other is the value of the array as the key value. If one of the arrays is empty,

Or if the number of elements in the two array is different, the function returns false

Array Array_combine (array keys,array values)

Example:

$a 1=array ("OS", "webserver");

$a 2=array ("Linux", "Apache");

Print_r (Array_combine ($a 1, $a 2));

4array_merge () function bar one or more arrays are merged into an array, and if the key name is repeated, the key value of the keys is the value corresponding to the last key name, if the array is a numeric index

The key name is re-indexed in a sequential way, noting that if a person enters an array only to the Array_merge () function, and the key name is an integer, the function returns the integer key name.

A new array whose key names are re-indexed starting with 0.

Array Array_merge (array array1 [, array array2 [, array ...])

Example:

$a 1=array ("a" = "Linux", "B" = "Apache");

$a 2=array ("c" = "MySQL", "b" = "PHP");

Print_r ($a 1, $a 2);

$a =array (3=> "PHP",4=> "MySQL");

Print_r (Array_merge ($a)); 0 Start re-indexing

The 5array_intersect () function is a computed array intersection that returns the result that the array contains all the values in the array that are being compared, and also all other parameter arrays, the key name remains unchanged

Array array_intersect (array Array1,array array2 [, array ...])

Example:

$a =array ("Linux", "Apache", "MySQL");

$b =array ("Linux", "Tomact", "MySQL");

Print_r (Array_intersect ($a, $b));

The 6.array_diff () function returns an array of two array difference sets, which includes all the values of the elements in the array being compared, but not in any other parameter array, returning the array with the key name unchanged

Array Array_diff (array Array1,array array2 [, array ...])

Example:

$a 1=array ("Linux", "MySQL", "Apache");

$a 2=array ("Linux", "MySQL", "Tomcat");

Print_r (Array_diff ($a 1, $a 2))

php1.9--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.