PHP Array

Techno PHP

The array is the collection of similar data items. The array is used for same data types.
Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same data type
. Array remove the data complexity.

An array stores the multiple values .


$fruits = array("Banana", "Mango ", "Orange");
echo "I like " . $fruits[0] . ", " . $fruits[1] . " and " . $fruits[2] . ".";

Index of an array start from the 0 .
$fruits[0] ----- Zero index number of array .

$fruits[1] ----- Index number one of array .

$fruits[2] ----- Index number two of array .

If you have a list of items (a list of fruit names, for example), store the fruit in single variables could look like this:




In another example of the array, we can define the index value one by one and print them like below example.



Sr No <?php echo"$x[0]"; ?>

Sr No <?php echo "$x[1]"; ?>

Sr No <?php echo "$x[2]"; ?>

Sr No <?php echo "$x[3]"; ?>

There are three type of arrays.

1. Index Array .

PHP index starts from 0. We can store number, string, an object in the PHP array. All array elements assigned to an index number by default.

Learn More

2.Two dimensional array .

Two dimensional array have rows and columns two-dimensional array is, in essence, a list of one-dimensional arrays. To declare a two-dimensional integer array of size [x][y].

Learn More

3.Associative Array

Associative array is one of the powerful and most efficient array in PHP .In associative array we can associate name with each array elements in PHP using => symbol.

Learn More