elibraryportal Logo

Array in PHP

1) An array is a special variable, which can hold more than one value at a time.

2) An array is used to store multiple values, in a single variable.

Array in PHP

Types of Arrays in PHP

There are three types of arrays . These are:

  1. Indexed array :- An array with a numeric key.
  2. Associative array :- Arrays with named keys .
  3. Multidimensional array :- An array containing one or more arrays .

1) Indexed Arrays in PHP

PHP index starts from 0. You can store number, string and object in PHP array.

Two examples shows in creating way an indexed array.

Example 1 :-

Output

 Array ( [0] => PHP [1] => Java [2] => .Net )

Example 2 :-

Output

 Season are: PHP, HTML, CSS and JS

2) Associative Arrays in PHP

Associative Arrays using this type of symbol =>

Example 1 :-

Output

 Peter salary: 350000
John salary: 450000
Kartik salary: 200000

Example 2:-

Output

 Peter salary: 350000
John salary: 450000
Kartik salary: 200000    

3) Multidimensional Arrays in PHP

A multidimensional array store date in tabular form and which is represented in matrix form row * column.

Example 1 :-

Output

 Volvo: In stock: 22, sold: 18.
BMW: In stock: 15, sold: 13.
Saab: In stock: 5, sold: 2.
Land Rover: In stock: 17, sold: 15.


Example 2 :-

Output

MultiDimensional array
Next Topic