PHP Common functions Summary (array part) shared version There will be some errors _php tutorial

Source: Internet
Author: User
Tags shuffle sorts
Function name use format input/output operation

Array Generation and Transformation:

The array () generates an array of arrays (mixed [...]) for arrays of values or, key = = value An array-type variable without

Array_combine () generates an array with the value of one array as the key name, and the other array value as the value array array_combine (array $keys, array $values) $keys to provide an array of keys, $ Values for arrays that provide a value for the array are not

Range () sets a specified range of cells array range (mix $low, Mix $high, [num $step]) $low minimum, $high Maximum, array of $step step composition None

Compact () establishes an array, including their variable names and values arr compact (mix $varname, [, Mix $ ...]) various variables, and arrays, are returned by the variable name as the key, the variable value is an array of values, and the variable can also be a multidimensional array. Recursive processing without

Array_fill () generates an array of arrays Array_fill (int $start, int $num, mix $value) with the given values to start, $num elements, $value returns the completed array for the filled contents without a

Array merging and splitting:

Array_chuk () divides an array into specified multiple array array_chunk (arr $input, int $size [, bool $preserve _keys]) $input manipulated array, $size each copy containing several elements, $ Preserve_keys Boolean, whether to preserve the multi-dimensional array after the key split is not

Array_merge () merges one or more arrays. If the key of the element is the same, the previous will be overwritten, the sequence of the index will not be overwritten, and only the arr array_merge (arr $arr 1[,arr $arr 2,...]) $arr 1 is manipulated array Returns the completed array without

Array comparison operations:

Array_diff () computes the difference set of arrays array Array_diff (arr $arr 1,arr $arr 2[,...]) Enter two or more arrays to compare the difference set of several array element values without

Array_intersect () computes the intersection of array array_intersect (arr $arr 1,arr $arr 2[,...]) to enter two or more arrays to compare the intersection of several array element values without

Array Lookup substitution operations:

Array_search () The given value from the array returns the key name Mix Array_search (Mix $need, arr $arr [bool $stric]) $need to find the string, $arr as the target array, $ Stric is ture and the variable type is also matched to return the key name successfully, the failure returns false none

Array_slice () Extracts a section of arr array_slice (arr $array, int $offset [, int $length [bool $p _key]) from the array $array the target array; $offset offset; $ length is truncated; $p _key:true the key name. The default is to re-give the key name $array the target array, $offset non-negative start from this offset, such as a negative value from the end of the distance from the beginning, if the $length is positive, then there will be so many units in the sequence, if not negative, The sequence is so far from the end of the range. No

Array_splice () Remove part of the array with other values instead of Arry array_splice (arr & $input, int $offset [, int $leng [, arr $rep]) $input as the destination array, $ Offset is offsets, $leng not remove all elements from $offset to the end, positive values remove so many cells, negative values remove the $OFFK to the end of the $leng so many units are replaced by the original array, note that the substitution of the key names in the array is not preserved, if the Rep will be replaced by the new array element in the original array

Array_sum () computes the sum of the number array_sum (arr $array) destination array for all the values in the array and returns the summation none

In_array () looks for a value in the array, case-sensitive bool In_array (mix $need, arr $array [, BOOL $str]) searches for $need in $array, and if $str is true, the check type also matches. Returns true if found, no return False No

Array_key_exists () checks whether the given key name exists in bool Array_key_exists (Mix $key, arr $serch) $key the key to find, $serch the target array returns if no

Array pointer operations:

Key ()

Current () alias POS ()

Next ()

Prev ()

End ()

Reset ()

List () assigns the values in the array to the variable void list (Mix $var 1[, $var 2 ...]) =arr $array

Array_shift ()

Array_unshift ()

The Array_push () array is finally pressed into multiple elements int Array_push (arr & $array, Mix $var 1[, $var 2 ...]) & $array destination Array, $var 1: Returns 1 for the join value for success, 0 for failure directly to the target array operation

Array_pop () array finally pops up an element mix Array_pop (arr & $array) & $array Returns the element values that are popped for the target array directly to the target array operation

Array key-value operation:

Shuffle () The array is scrambled, the reserved key name bool Shuffle (arr & $array) input array returns true in the scrambled order after the key name does not change

Count ()

Array_flip () Exchange the keys and values in the array arr. Array_flip (arr $trans) $trans The array that is being manipulated to return the completed arrays without

The Array_keys () returns an array of all the keys that make up the arr Array_keys (arr $input [, Mix $search [, BOOL $str]]) $search A value that returns only the key name corresponding to the value, $str true. Also compare types that return a key name to an array that has no

Array_values () returns all the values in the array, forming an array of arrays Array_values (array $input)

Array_reverse () returns an array of elements in the reverse order of arr Array_reverse (arr $input [, BOOL $key]) Enter the target array, $key true to preserve an array with the same key name order as the previous one without

Array_count_values () counts the number of occurrences of a value in an array of arrays Array_count_values (array $input) $input is an array of operands with the value of input as the key, the number of occurrences of the array of values is not

Array_rand () randomly extracts one or more elements from an array, note the key name!!! Mix Array_range (arr $input [, int $num]) $input as the target array, $num to extract several elements to return the key of the extracted element, if one is a key name, and multiple elements, these keys are indexed as values to return an array of

each ()

Array_unique () Moves the duplicate values in 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) input destination array key name remains unchanged return no duplicates array no

To sort an array:

Sort () sorts (from low to high), does not retain key name bool Sort (arr & $array [, int $flag]) destination array successfully returns TRUE, failure returns false to reorder group elements and change key names

Rsort () reverse array (from high to low), non-reserved key name bool Rsort (arr & $array [, int $flag]) destination arrays successfully return True, failure returns false to rearrange array elements, and change key names

Asort () array sorting, keeping the index relationship bool Asort (arr & $array [, int $flag]) destination arrays successfully returns TRUE, Failure returns false to sort the group, preserving the original index or key

Arsort () reverse-order the array, keeping the index relationship

Ksort () The array is sorted by key name bool Ksort (arr & $array [int $flag]) destination arrays successfully returns True, failed returns false to sort key names, preserves key value correspondence

Krsort () An array in reverse order by key name

Natsort () "" "Natural Algorithm" "Sort array, keep key value relationship" bool Natsort (arr & $array) Destination array successfully returns TRUE, failure returns false to naturally sort values, preserves key-value correspondence

Natcasesort () Natural sort, case-insensitive bool Natcasesort (arr & $array) Destination array successfully returns TRUE, Failure returns false case-insensitive sorting of values, preserving key-value correspondence

From the Battlefield diary _lamp brother Lian

http://www.bkjia.com/PHPjc/478505.html www.bkjia.com true http://www.bkjia.com/PHPjc/478505.html techarticle function name use format input/output operation array generation and conversion: Array () generates an array of arrays (mixed [...]) for the value of the arrays or, the key = value of an array type variable without array_combine (...

  • 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.