Array functions in php with related Details

Introduction

Here, On this Page, I'm publishing the list and details about all php array functions. Array functions allows PHP programmers to interact with and manipulate arrays in various ways. Arrays are essential for storing, managing, and operating on sets of variables. Simple and Multidimensional, Both types of arrays are supported in PHP, Which are either user created or created by another function. There are several functions in Huge Library of PHP functions which outputs/returns result in the form of arrays (Termed as "populating arrays") and database handling functions are one and most important ones.

What is array in PHP ? (Official Statement)

An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.

Array Functions in PHP
Array Functions in PHP

Syntax of Array

array(  key =>  value
     , ...
     )
// key may only be an integer or string
// value may be any value of any type

List of All PHP Array Functions

Function
Description
Syntax
array_change_key_case
Changes all keys in an array
array array_change_key_case ( array $input [, int $case = CASE_LOWER ] )
array_chunk
Split an array into chunks
array array_chunk ( array $input , int $size [, bool $preserve_keys = false ] )
array_combine
Creates an array by using one array for keys and another for its values
array array_combine ( array $keys , array $values )
array_count_values
Counts all the values of an array
array array_count_values ( array $input )
array_diff_assoc
Computes the difference of arrays with additional index check
array array_diff_assoc ( array $array1 , array $array2 [, array $... ] )
array_diff_key
Computes the difference of arrays using keys for comparison
array array_diff_key ( array $array1 , array $array2 [, array $... ] )
array_diff_uassoc
Computes the difference of arrays with additional index check which is performed by a user supplied callback function
array array_diff_uassoc ( array $array1 , array $array2 [, array $... ], callback $key_compare_func )
array_diff_ukey
Computes the difference of arrays using a callback function on the keys for comparison
array array_diff_ukey ( array $array1 , array $array2 [, array $ ... ], callback $key_compare_func )
array_diff
Computes the difference of arrays
array array_diff ( array $array1 , array $array2 [, array $ ... ] )
array_fill_keys
Fill an array with values, specifying keys
array array_fill_keys ( array $keys , mixed $value )
array_fill
Fill an array with values
array array_fill ( int $start_index , int $num , mixed $value )
array_filter
Filters elements of an array using a callback function
array array_filter ( array $input [, callback $callback ] )
array_flip
Exchanges all keys with their associated values in an array
array array_flip ( array $trans )
array_intersect_assoc
Computes the intersection of arrays with additional index check
array array_intersect_assoc ( array $array1 , array $array2 [, array $ ... ] )
array_intersect_key
Computes the intersection of arrays using keys for comparison
array array_intersect_key ( array $array1 , array $array2 [, array $ ... ] )
array_intersect_uassoc
Computes the intersection of arrays with additional index check, compares indexes by a callback function
array array_intersect_uassoc ( array $array1 , array $array2 [, array $ ... ], callback $key_compare_func )
array_intersect_ukey
Computes the intersection of arrays using a callback function on the keys for comparison
array array_intersect_ukey ( array $array1 , array $array2 [, array $... ], callback $key_compare_func )
array_intersect
Computes the intersection of arrays
array array_intersect ( array $array1 , array $array2 [, array $ ... ] )
array_key_exists
Checks if the given key or index exists in the array
bool array_key_exists ( mixed $key , array $search )
array_keys
Return all the keys or a subset of the keys of an array
array array_keys ( array $input [, mixed $search_value [, bool $strict = false ]] )
array_map
Applies the callback to the elements of the given arrays
array array_map ( callback $callback , array $arr1 [, array $... ] )
array_merge_recursive
Merge two or more arrays recursively
array array_merge_recursive ( array $array1 [, array $... ] )
array_merge
Merge one or more arrays
array array_merge ( array $array1 [, array $... ] )
array_multisort
Sort multiple or multi-dimensional arrays
bool array_multisort ( array &$arr [, mixed $arg = SORT_ASC [, mixed $arg = SORT_REGULAR [, mixed $... ]]] )
array_pad
Pad array to the specified length with a value
array array_pad ( array $input , int $pad_size , mixed $pad_value )
array_pop
Pop the element off the end of array
mixed array_pop ( array &$array )
array_product
Calculate the product of values in an array
number array_product ( array $array )
array_push
Push one or more elements onto the end of array
int array_push ( array &$array , mixed $var [, mixed $... ] )
array_rand
Pick one or more random entries out of an array
mixed array_rand ( array $input [, int $num_req = 1 ] )
array_reduce
Iteratively reduce the array to a single value using a callback function
mixed array_reduce ( array $input , callback $function [, mixed $initial = NULL ] )
array_replace_recursive
Replaces elements from passed arrays into the first array recursively
array array_replace_recursive ( array &$array , array &$array1 [, array &$... ] )
array_replace
Replaces elements from passed arrays into the first array
array array_replace ( array &$array , array &$array1 [, array &$... ] )
array_reverse
Return an array with elements in reverse order
array array_reverse ( array $array [, bool $preserve_keys = false ] )
array_search
Searches the array for a given value and returns the corresponding key if successful
mixed array_search ( mixed $needle , array $haystack [, bool $strict = false ] )
array_shift
Shift an element off the beginning of array
mixed array_shift ( array &$array )
array_slice
Extract a slice of the array
array array_slice ( array $array , int $offset [, int $length [, bool $preserve_keys = false ]] )
array_splice
Remove a portion of the array and replace it with something else
array array_splice ( array &$input , int $offset [, int $length = 0 [, mixed $replacement ]] )
array_sum
Calculate the sum of values in an array
number array_sum ( array $array )
array_udiff_assoc
Computes the difference of arrays with additional index check, compares data by a callback function
array array_udiff_assoc ( array $array1 , array $array2 [, array $ ... ], callback $data_compare_func )
array_udiff_uassoc
Computes the difference of arrays with additional index check, compares data and indexes by a callback function
array array_udiff_uassoc ( array $array1 , array $array2 [, array $ ... ], callback $data_compare_func , callback $key_compare_func )
array_udiff
Computes the difference of arrays by using a callback function for data comparison
array array_udiff ( array $array1 , array $array2 [, array $ ... ], callback $data_compare_func )
array_uintersect_assoc
Computes the intersection of arrays with additional index check, compares data by a callback function
array array_uintersect_assoc ( array $array1 , array $array2 [, array $ ... ], callback $data_compare_func )
array_uintersect_uassoc
Computes the intersection of arrays with additional index check, compares data and indexes by a callback functions
array array_uintersect_uassoc ( array $array1 , array $array2 [, array $ ... ], callback $data_compare_func , callback $key_compare_func )
array_uintersect
Computes the intersection of arrays, compares data by a callback function
array array_uintersect ( array $array1 , array $array2 [, array $ ... ], callback $data_compare_func )
array_unique
Removes duplicate values from an array
array array_unique ( array $array [, int $sort_flags = SORT_STRING ] )
array_unshift
Prepend one or more elements to the beginning of an array
int array_unshift ( array &$array , mixed $var [, mixed $... ] )
array_values
Return all the values of an array
array array_values ( array $input )
array_walk_recursive
Apply a user function recursively to every member of an array
bool array_walk_recursive ( array &$input , callback $funcname [, mixed $userdata ] )
array_walk
Apply a user function to every member of an array
bool array_walk ( array &$array , callback $funcname [, mixed $userdata ] )
array
Create an array
array array ([ mixed $... ] )
arsort
Sort an array in reverse order and maintain index association
bool arsort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
asort
Sort an array and maintain index association
bool asort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
compact
Create array containing variables and their values
array compact ( mixed $varname [, mixed $... ] )
count
Count all elements in an array, or properties in an object
int count ( mixed $var [, int $mode = COUNT_NORMAL ] )
current
Return the current element in an array
mixed current ( array &$array )
each
Return the current key and value pair from an array and advance the array cursor
array each ( array &$array )
end
Set the internal pointer of an array to its last element
mixed end ( array &$array )
extract
Import variables into the current symbol table from an array
int extract ( array &$var_array [, int $extract_type = EXTR_OVERWRITE [, string $prefix ]] )
in_array
Checks if a value exists in an array
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
key
Fetch a key from an array
mixed key ( array &$array )
krsort
Sort an array by key in reverse order
bool krsort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
ksort
Sort an array by key
bool ksort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
list
Assign variables as if they were an array
array list ( mixed $varname [, mixed $... ] )
natcasesort
Sort an array using a case insensitive "natural order" algorithm
bool natcasesort ( array &$array )
natsort
Sort an array using a "natural order" algorithm
bool natsort ( array &$array )
next
Advance the internal array pointer of an array
mixed next ( array &$array )
pos
Alias of current()
 
prev
Rewind the internal array pointer
mixed prev ( array &$array )
range
Create an array containing a range of elements
array range ( mixed $start , mixed $limit [, number $step = 1 ] )
reset
Set the internal pointer of an array to its first element
mixed reset ( array &$array )
rsort
Sort an array in reverse order
bool rsort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
shuffle
Shuffle an array
bool shuffle ( array &$array )
sizeof
Alias of count()
 
sort
Sort an array
bool sort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
uasort
Sort an array with a user-defined comparison function and maintain index association
bool uasort ( array &$array , callback $cmp_function )
uksort
Sort an array by keys using a user-defined comparison function
bool uksort ( array &$array , callback $cmp_function )
usort
Sort an array by values using a user-defined comparison function
bool usort ( array &$array , callback $cmp_function )

Rate this Article ???

See results without voting

So, that was the huge list of PHP array functions which simplifies the the task task of creating, manipulating and destroying arrays in php. How it is easy to navigate through them for you.

If you were having problem in understanding syntax's, then, You can copy them from here to notepad or on other text editing tool to get a better view of it.

More by this Author


Comments 1 comment

Manoj D.Nemade 5 years ago

Nice....this will help a lot to us......................

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working