Best PHP array functions
During the writing PHP code in process of developing web applications, we use various programming techniques. But i think that there is hard to find any class or even a function which doesn’t manipulate with arrays. Let’s see what is the most useful PHP functions that manipulate with arrays.
&$array, callback $funcname, $username) – function apply any of your functions to every member of an array
Very useful function when you want to do some data processing on each array element.
array_slice ( array
$length) – returns part of array specified by the
This really can be helpful when when you want to make sub-array from main array.
array_chunk ( array
$size , bool
$preserve_keys = false ) – split an array into
size large chunks.
Splits one big array into smaller chunks of arrays with same size. Magic function!
array_reverse ( array
$array , bool
$preserve_keys = false ) – takes an array and reverse its content
This function speak for it self.
array_flip ( array
$trans ) – switches keys with values
This won’t be needed you all the time, but it can save you some time when you are in situation to flip keys with values.
array_keys ( array
$search_value ) – get all array keys
From your array this function returns an array which contains keys from main array. Can be very useful!
array_merge ( array
$array1 [, array
$... ] ) – merge one or more arrays
If you have more then one array, and you want to manipulate with them together, this is probably what you need.
array_fill ( int
$start_index , int
$value ) – Fill array with parameter on defined positions
With this function you can fill some parts of an array with values that you want.
array_pop ( array
&$array ) – Pop last value of an array and returns that array.
Simple function that remove last element of an array, pretty straight forward.
sort ( array
&$array [, int
$sort_flags = SORT_REGULAR ] ) – Sort an array
Sort an array based on sort flags.
This is the most common array manipulation functions that i am using in everyday programming, although i probably forgot to mentioned some function.
If you have any other php array function that you often using that is not on this list, please write comment and notice other users about it.
No related posts.