SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

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.

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.
Further readings
 PHP array
Array functions in PHP
array : Creating an Array
array_diff Difference of two arrays
array_count_values counting the frequency of values inside an array
count : sizeof Array Size or length
array_push : Adding element to an Array
array_sum : Array Sum of all elements
Displaying the elements of an array
Array checkbox
in_array : IN Array to search for elements inside an array
array_rand : Random elements of Array
array_unique : Array Unique values
Breaking of strings to create array using split command
Session Array to maintain data in different pages
unset : Deleting elements of an array by using its key or value
sort: Simple sorting of PHP array
rsort: Reverse sorting of PHP array
asort: Maintaining index of the elements after sorting
arsort: Sorting in reverse order for a PHP array
ksort: Array key Sorting in PHP
krsort: Array reverse key Sorting in PHP
usort: Sorting array by using user defined function
























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

Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
PHP Tutorials
Array Functions
PHP Monthly Planner
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.