Multidimensional Array in PHP | Definition | Syntax | Examples

Hello Friend how are you i hope you all are doing well. Today in this post we will learn about Multidimensional Array in PHP like what is Multidimensional Array, Syntax of  Multidimensional Array, Initialization of Multidimensional Array with examples. If you want to learn PHP in very simple easy way then this post will help you definitely.

Multidimensional Array in PHP

1.The array inside array is called multidimensional array.
2.When an array contains one or more array then it is called Multidimensional array.
3.array() function is used to create array in PHP.

Multidimensional array using indexed array:

 
<?php
$matrix=array(array(80,50,20),array(70,40,10),array(90,60,30));
for($i=0;$i<=2;$i++)
{
  for($j=0;$j<=2;$j++)
  {
  echo $matrix[$i][$j]." ";
  }
  echo "<br>";
}
/*
OUTPUT
80 50 20 
70 40 10 
90 60 30 
*/
?>

Multidimensional array using associative array

 
<?php
$student=array(
"Rocky"=>array(
       "rollno"=>"205",
	   "branch"=>"Computer science"
	   ),
"Raj"=>array(
       "rollno"=>"209",
	   "branch"=>"Information technology"
	   ),
"Tony"=>array(
       "rollno"=>"206",
	   "branch"=>"Civil Engineering"
	   )
);
/* Printing Rocky information */ 
echo $student['Rocky']['rollno']."<br>";
echo $student['Rocky']['branch']."<br>";
/* Printing Tony information */ 
echo $student['Tony']['rollno']."<br>";
echo $student['Tony']['branch']."<br>";
/*
OUTPUT
205
Computer science
206
Civil Engineering
*/

Types of Array in PHP 

There are three types of Array in PHP
1.Indexed Array Click here to learn.
2.Associative Array Click here to learn.
3.Multi Dimension Array Click here to learn.

Request:-If you found this post helpful then let me know by your comment and share it with your friend. 

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

Thanks

Post a Comment

0 Comments