What is an Array

An array stores multiple values in one single variable:


$fruits = array("Apple", "Orange", "Banana");


What is PHP Arrays?

Arrays are complex variables that allow us to store more than one value or a group of values under a single variable name. Let's suppose you want to store fruits in your PHP script. Storing the fruits one by one in a variable could look something like this:

$fruit1 = "Apple";
$fruit2 = "Orange";
$fruit3 = "Banana";


In PHP, the array() function is used to create an array:



In PHP, there are three types of arrays:

  • Indexed or Numeric Arrays: An array with a numeric index where values are stored linearly.
  • Associative Arrays: An array with a string index where instead of linear storage, each value can be assigned a specific key.
  • Multidimensional Arrays: An array which contains single or multiple array within it and can be accessed via multiple indices.