PHP Array: Indexed,Associative, Multidimensional
index associative multidimensional array in php; Through this tutorial, you will learn about PHP Indexed, Associative, Multidimensional array with examples.

PHP Array: Indexed,Associative, Multidimensional
Basically PHP array is a special type of variable in which is used to collect multiple data in it.
In other words, An array is a special types of variable, which can hold more than one value at a time.
Create a New Array in PHP
You can use the below syntax for creating a new array in PHP:
array();
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
PHP Indexed Arrays
Here, we will create indexed arrays in PHP:
$lang = array("PHP", "PYTHON", "JAVASCRIPT");
Example of Indexed Arrays:
In the below example, we will create an indexed array named $lang. The $lang is contained three values.
PHP Array Length:
PHP Count() function is used to calculate the length of the array. It will return the length of the array
Loop with Indexed Arrays In PHP
Here, you will learn, how you can use the for loop with an indexed array in PHP:
PHP Associative Arrays
Associative Arrays in PHP. Associative arrays are used to store key value pairs.
$subjects = array("PHP"=>"50", "PYTHON"=>"55", "JAVASCRIPT"=>"45");
Example of Associative Arrays:
For example, to store the marks of the different subjects in an array, a numerically indexed array would not be the best choice.
For Loop with Associative Arrays In PHP
Here, you will learn, how you can use for loop with associative an array in PHP:
Multidimensional Arrays In PHP
In PHP, A multidimensional array is an array containing one or more arrays in it.
We will create a multidimensional array:
$cars = array ( array("Volvo",22,18), array("BMW",15,13), array("Saab",5,2), array("Land Rover",17,15) );
Example of Multidimensional Arrays
For loop with Multidimensional Array in PHP:
Foreach Loop Through an Associative Array PHP
See the below example for foreach loop with an associative array in PHP
Foreach loop through multidimensional array in PHP
Foreach loop is mainly used for looping through array values. Here you will learn how you can use foreach loop with PHP arrays: