SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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.

Difference of two arrays

We can generate a resultant third array by differentiating two arrays

array_count_values

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.

array_map function for arrays

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

Adding elements to array

We can add elements to an existing array by using array_push

Array sum

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

in_array

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

array_rand

Randomly collecting elements of an array

array_unique

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

Sorting all elements of an array by sort command

Reverse Sorting

Rsort command can be used to sort the elements in reverse order

Sorting & maintaining same index ( asort )

By using asort we can sort the elements and by maintaining the associated index of each element.

Reverse Sorting with associated key

We can reverse sort the elements of array and maintain the associated key with elements.

Sorting the key ( ksort)

We can sort the array on key and maintain the association with the elements.

Sorting the key in reverse order ( krsort)

Key can be sorted in reverse order and the association is maintained.

Sorting based on requirement (usort)

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

Displaying elements

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

Filtering elements

Creating new array with filter ( callback ) function

Using user function

Passing user defined function to each element of an array

Google+
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust



Array Functions
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer