PHP ARRAYS - Code

PHP COOKIES Previous Next PHP Numeric Arrays


An array is a special type of variable which can store multiple values in one single variable.

If you have a list of names, storing them in single variables could look like this.

$name1="Car"; $name2="Bus"; $name3="Train";

Suppose there are hundred such name. Declaring each name as a separate variable becomes tedious.

Hence one can declare an array of names containing 100 elements and refer to it by one single name.

And one can access the values by refferring to the array name.

Each element in the array has its own index so that it can be easily accessed.

ex: $names=array("Car","Bus","Train");

In PHP, there are three kind of arrays.

  1. Numeric array - An array with a numeric index.
  2. Associative array - An array where each ID key is associated with a value.
  3. Multidimensional array - An array containing one or more arrays.

Tags: PHP ARRAYS PHP Code Programming Language


Was this helpful ?