PHP Array

arrays are used to store more than one value in a single variable. For example, if you have a list of fruits you can store their names in a single variable.

<?php
 $array = array('Apple', 'Mango', 'Banana', 'Apricot', 'Blackberry');
?>

This is equivalent to the following example, in which indexes are assigned manually:

<?php
 $array[0] = 'Apple';
 $array[1] = 'Mango';
 $array[2] = 'Banana';
 $array[3] = 'Apricot';
 $array[4] = 'Blackberry';
?>

Types of Arrays in PHP

  1. Indexed array — An array with a numeric key.
  2. Associative array — An array where each key has its own specific value.
  3. Multidimensional array — An array containing one or more arrays within itself.