W e b t u t o r i a l s

Define PHP

PHP Installation

PHP INI File

PHP Case Sensitivity

PHP Variable

PHP Echo & Print

PHP Operators

PHP Receiving Input

PHP Decision Making

PHP Loops

PHP Jumping Statement

PHP Image Gallery

PHP Arrays

PHP Date Functions

PHP String Functions

PHP Math Functions

PHP Functions

PHP Variable Scope

PHP Constant Variable

PHP Superglobals

PHP Form Validation

PHP Include Statement

PHP Filter

PHP File Handling

PHP File Upload

PHP Cookies

PHP Session

PHP Send Emails

PHP Captcha

PHP-MySQL Connectivity

PHP MySQL Select

PHP MySQL Insert

PHP MySQL Delete

PHP MySQL Update

PHP Arrays

An array is a special variable, which can hold more than one value at a time. There are three different kind of arrays and each array value is accessed using an ID which is called array index.

Types of Arrays:
1D Array / Numeric array.
Associative arrays.
2D Arrays.

PHP 1D Array / Numeric array

Single Dimensional array is a array with a numeric index. Values are stored and accessed in linear fashion.

Example 1.1: Single Dimensional Array. Example 1.2: Display all Array values using Foreach Loop. Example 1.3: Display all color values in array using Foreach Loop.
Count and sizeof function is use to calculate array length. Its Syntax is:
echo sizeof($web);
echo count($web); 

Associative array

The associative arrays are very similar to numeric arrays in term of functionality but they are different in terms of their index number. Associative array will have their index as string so that you can establish a strong association between key and values.

Example 2: Associative array

PHP 2D Array / Multidimensional Array

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

Example 3: Multidimensional array. Display 3 Student marks.
Note: Get The Length of an Array - The count() Function: echo count($marks);

PHP Arrays Sort Functions

Function Description
sort() Sort arrays in ascending order. Syntax: sort($array);
rsort() Sort arrays in descending order
asort() Sort associative arrays in ascending order, according to the value
ksort() Sort associative arrays in ascending order, according to the key
arsort() Sort associative arrays in descending order, according to the value
krsort() Sort associative arrays in descending order, according to the key