Array In Php

Array In Php

An array is a data structure which is stores one or more similar data type values in a single variable.

Example : if you want to store 100 numbers then instead of defining 100 variables its easy to define an array of 100 length.

There are three type of arrays and each array value is accessed using an ID  which is called array index.

Numeric array – An array with a numeric index is called numeric array.

Associative array – An array with strings index is called associatetive arry. This stores element values in association with key values rather than in a strict linear index order.

Multidimensional array – An array containing one or more arrays and values are accessed using multiple indexes.

What are Arrays?

This is very easy to tell but sometime it is really difficult to understand the dynamics of arrays, after functions, arrays are one of the greatest mechanism of programming to solve the problem of data maintenance and presentation.

Arrays are collections of data in a particular way.

In this article I have listed only some very important functions, but it does not mean that other functions are not important , every function has its importance in the context of that’s functions requirement.

Some Array Functions are :


This function split an array into chunks, it is useful to divide a large array into smaller once. You may also have an array with less values at the end. You get the arrays as members of a multidimensional array indexed with numbers starting from zero.


Creates an array by using one array for keys and another for its values
Returns FALSE if the number of elements for each array isn’t equal or if the arrays are empty.


This function returns an array containing all the values of array1 that are not present in any of the other array(used 2 two or more array ). Note that keys are preserved.


Exchanges all keys with their associated values in an array This function returns an array in flip order, i.e. keys from trans become values and values from trans become keys.


array_merge() merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array. If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.
If only one array is given and the array is numerically indexed, the keys get reindexed in a continuous way.


This is one of shortest and easy but yet very useful function, this function return the last element of array,. A simple use is to get the extension of any file while using it with explode function.


array_rand function return a single random key from an array. it will be return an random key array if you specify the length of random key in array_ran function


array_reverse function will reverse the elements in an array.This function can take one or two parameters. The first parameter is the target array which is to be reversed, and the second parameter is optional which can be set to true or false. and use "true" to preserve the keys in the second parameter, Use "false" to reindex the array keys.


Searches the array for a given value and returns the corresponding key if successful


Extract a slice of the array


Removes duplicate values from an array


Apply a user function to every member of an array


I have used this function almost in my every application, using this function you can even simulate the register_globals=On effect in the PHP version where they are Off (They should be off in any ideal PHP installation.)


Checks if a value exists in an array


Sort an array using a “natural order” algorithm


Shuffle an array

, , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">