PHP array

PHP array are useful to store multiple data using a single variable. Using index of the PHP array we can access the stored variables. Indexes to an array element can either a number or a string. An array is a list variables. Each item in an array is commonly known as element of the array and can be accessed directly via its index.

Creating an Array

In PHP there are different ways to create or declare an array. We can assign keys to each element of the array.

Displaying elements

We can display all elements of the array by different methods.

Difference of two arrays

We can generate a resultant third array by differentiating two arrays


We can calculate the frequency of occurrence of elements inside a array.

Size of the array

How many elements are present inside the array? We can find out by count or sizeof() function.

Maximum minimum value of array

Using max and min function we can get maximum and minimum value of an array in PHP.

Array of keys of a main array

We can the array of keys from a array by using array_keys function in PHP.

Adding elements to array

We can add elements to an existing array by using array_push

Adding two arrays

We can add one array to other by using array_merge

Array sum

We can get total value or sum of the elements present inside an array


Check the presence of an element inside an array. Returns True of False


Randomly collecting elements of an array


We can get a set of unique value from an array.

Breaking string

We can split a string and create a array by using all words.

Session array

We can create a session array and carry same data across the pages.

Deleting elements

By using unset command we can delete elements of an array


Sorting all elements of an array by sort command

Sorting based on requirement (usort)

We can use one user defined function and sort the elements.

array_map function for arrays

WE can apply native functions or user defined function to each elements of array by using using array_map.

Filtering elements

Creating new array with filter ( callback ) function

Using user function

Passing user defined function to each element of an array

Be the first to post comment on this article :


Post Comment This is for short comments only. Use the forum for more discussions.

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2015 All rights reserved worldwide Privacy Policy Disclaimer