PHP array functions

Source: Internet
Author: User
Tags explode expression engine

Is_array

(PHP 4, PHP 5, PHP 7)

is_array- Detecting If a variable is an array

Is_array Mixed $var )

If var it is an array, TRUE It is returned FALSE , otherwise.

Explode

(PHP 4, PHP 5, PHP 7)

explode- using one string to split another string

Array Explode string $delimiter string $string $limit ] )

This function returns an array of strings, each of which is string a substring separated by a string delimiter as a boundary point.

Parameters:

delimiter

The delimited character on the boundary.

string

The input string.

limit

If the limit parameter is set and is a positive number, the returned array contains the most limit elements, and the last element will contain string the remainder.

If the limit argument is a negative number, limit all elements except the last-element are returned.

If limit it is 0, it will be treated as 1.

For historical reasons, although implode () can receive two parameter sequences, explode () does not work. You must make sure that separator the arguments string precede the arguments.

return value:

This function returns an array of strings , each of which is string a substring separated by a string delimiter as a boundary point.

If the delimiter string is empty (""),explode () returns FALSE . If the delimiter contained value is string not found in, and a negative number is used, limit an empty array is returned, otherwise string an array containing a single element is returned.

Implode

(PHP 4, PHP 5, PHP 7)

implode-converts The value of a one-dimensional array to a string

Description
string implode string $glue Array $pieces )
string implode Array $pieces )

glueconcatenate the value of a one-dimensional array into a string.

Note:

For historical reasons,implode () can receive two parameter sequences, but explode () does not work. However, you can avoid confusion by order in the document.

Parameters:

glue

The default is an empty string.

pieces

The array you want to convert.

return value:

Returns a string whose contents are the values of an array separated by glue.

Split

(PHP 4, PHP 5)

split- using regular expressions to split a string into an array

Description
Array Split string $pattern string $string $limit ] )

Tip

The Preg_split () function uses Perl-compatible regular expression syntax, which is often a faster alternative than split () . If you don't need the power of a regular expression, use explode () faster, so you don't incur the waste of the regular expression engine.

This function returns an array of strings, each of which is a string case-sensitive regular expression that is a substring that is pattern separated by a boundary. If set limit , the returned array contains at most limit one cell, and the last cell contains all the string remaining parts of the. If there is an error, split () returns FALSE .

If there are pattern n matching items in a string, the returned array will contain n+1 cells. For example, if it is not found pattern , it returns an array of only one cell. Of course, string this is true if it is empty.

Note pattern is a regular expression. If you want to use a split character that is a special character in a regular expression, first escape it.

Preg_split

(PHP 4, PHP 5, PHP 7)

preg_split- separating strings by a regular expression

Description
Array Preg_split string $pattern string $subject $limit $flags = 0]])

Separates the given string by a regular expression.

Parameters:

pattern

The pattern used for the search, in string form.

subject

Input string

limit

If specified, the maximum number of substrings to be delimited is only limit one, and the last substring returned will contain all remaining parts. A limit value of 1, 0, or null means "No Limit", and as a standard for PHP, you can skip the flags setting by using NULL.

flags

flags Can be any combination of the following tags (in bits or operations | combination):

PREG_SPLIT_NO_EMPTY
If this tag is set, preg_split () will return to the non-empty part after the separation.
PREG_SPLIT_DELIM_CAPTURE
If this tag is set, the parentheses expression in the pattern used for the separation will be captured and returned.
PREG_SPLIT_OFFSET_CAPTURE

If this tag is set, the string offset will be appended to each occurrence of the match returned. Note: This will change each element in the returned array so that each element becomes a delimited substring of the first 0 elements, and the first 1 elements are subject an array of offsets in the substring.

return value:

Returns an pattern array of substrings that are separated by a boundary subject .

Comments: Tip

If you don't need regular expression functionality, you can have faster (and simpler) choices like explode () or str_split ().

Tip

If there is no successful match, an array is returned, containing a single element, the input string.

unset

(PHP 4, PHP 5, PHP 7)

unset- Releasing the given variable

Description
unset Mixed $var mixed $ ...] )

unset () destroys the specified variable.

The behavior of unset () in a function depends on the type of variable you want to destroy.

If you unset () a global variable in a function, only the local variable is destroyed, and the variable in the calling environment keeps the same value as before the call to unset () .

If you want to unset () a global variable in a function, you can use $GLOBALS an array to implement the

If you unset () A variable passed by reference in a function, only the local variable is destroyed, and the variable in the calling environment keeps the same value as before the call to unset () .

If a static variable is unset () in the function, this static variable will be destroyed inside the function. However, when this function is called again, the static variable is restored to the value before it was last destroyed.

Parameters:

var

The variable to be destroyed.

...

Other variables ...

return value:

no return value.

Comments:

Note: because it is a language constructor and not a function, it cannot be called by a mutable function.

Note:

It is possible to unset even object properties visible in current context.

Note:

$thiscould not be destroyed in the object before PHP 5.

Note:

This overloaded method is called if __unset () is defined when unset () is an Unreachable object property.

  • array_change_key_case-returns an array of string key names that are all lowercase or uppercase
  • array_chunk-splits an array into multiple
  • array_column-returns a column specified in the array
  • Array_combine-creates an array with the value of an array as its key 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-Calculating the difference set of an array using the key name comparison
  • array_diff_uassoc-uses the user-supplied callback function to do an index check to calculate the difference set of the array
  • array_diff_ukey-using a callback function to compare the difference set of an array to a key name
  • array_diff-Calculating the difference set of an array
  • array_fill_keys-fills an array with the specified key and value
  • 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_key-calculating the intersection of an array using the key name comparison
  • 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 the key names
  • Array_intersect-computes the intersection of an array
  • array_key_exists-checks whether the given key name or index exists in the array
  • array_keys-returns some or all of the key names in the array
  • Array_map-the callback function to the cell of the given array
  • array_merge_recursive-to 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 the stack)
  • 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 the stack)
  • array_rand-random extraction of one or more cells from an array
  • array_reduce-iteratively to simplify the array to a single value with a callback function
  • Array_replace_recursive-replaces the elements of the first array with the passed array recursion
  • Array_replace-replaces the elements of the first array with the passed array
  • array_reverse-returns an array of cells in reverse order
  • array_search-searches for the given value in the array, and returns the corresponding key name if successful
  • Array_shift-moves the cell at the beginning of the array to a group
  • array_slice-remove a paragraph from an array
  • array_splice-remove part of the 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_uintersect_assoc-with index Check the intersection of the computed array, using the callback function to compare the data
  • array_uintersect_uassoc-with index Check the intersection of computed arrays, using callback functions to compare data and indexes
  • Array_uintersect-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-applying user functions recursively to each member in an array
  • Array_walk-uses a user-defined function to do callback processing for each element in the array
  • array-creating a new array
  • arsort-an array in reverse order and maintain an index relationship
  • asort-sorting an array and maintaining an index relationship
  • compact-create an array, including the variable names and their values
  • count-count the number of cells in an array or the number of properties in an object
  • current-returns the current cell in the array
  • each-returns the current key/value pair in the array and moves the array pointer forward one step
  • end-the inner pointer of an 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_exists-alias Array_key_exists
  • key-getting the key name from the associative array
  • krsort-an array in reverse order by key name
  • ksort-sorting arrays by key name
  • List-assigns the values in the array to some variables
  • natcasesort-sorting of case-insensitive letters using the "natural sort" algorithm for arrays
  • natsort-using the "natural sort" algorithm to sort arrays
  • next-moves the inner pointer in the array forward one
  • Aliases for Pos-current
  • prev-the internal pointer of the array back to a
  • range-creating an array containing the specified range of cells
  • reset-the inner pointer of an array to the first cell
  • rsort-reverse sequence of an array
  • shuffle-Array is scrambled
  • Aliases for Sizeof-count
  • sort-sorting an array of arrays
  • 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 key names in an array
  • usort-using a user-defined comparison function to sort values in an array

PHP array 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.