PHP Arrays

An array stores multiple values in one single variable:

What is an Array?

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

An array is a data structure in programming that allows you to store multiple values under a single variable name.

It is a way to organize related data elements and access them using indexes or keys. Arrays provide a convenient and efficient way to work with collections of data.

In simple terms, you can think of an array as a container that holds multiple values. Each value in the array is called an element. Elements within an array are typical of the same data type, although PHP allows arrays to contain elements of different types.

$item1 = "Laptop";
$item2 = "Mobile";
$item3 = "Tab";

In PHP, there are three types of arrays:

  • Indexed arrays – Arrays with a numeric index
  • Associative arrays – Arrays with named keys
  • Multidimensional arrays – Arrays containing one or more arrays

Overall, an array is a fundamental data structure that allows you to store and manipulate multiple values efficiently, providing a convenient way to organize and access data in programming languages like PHP.