var $array = array(‘hello” , “Welcome” , “to PHP ” , “Interview Questions”);
Basically in PHP there are three type of arrays :
- Indexed Arrays
- This means the arrays with the numeric index or keys .
- It aromatically starts with 0 index or initialise 0 itself .
- Associative arrays are the arrays which uses the user defined names for as the keys.
Multidimensional arrays is the array which which stores one or many ( group of arrays ) at single place or on variables.
So lets go with an example :
Let suppose as a students in a class
$students = array (
array(“Joe”,14,9),
array(“John”,15,10),
array(“Hari”,16,11),
array(“Lakhan”,17,12)
);
So we can print is as :
<?php
echo $students[0][0].” is “.$students[0][1].” years old and study in “.$students[0][2].”.<br>”;
echo $students[1][0].” is “.$students[1][1].”years old and study in “.$students[1][2].”.<br>”;
echo $students[2][0].” is “.$students[2][1].”, years old and study in “.$students[2][2].”.<br>”;
echo $students[3][0].” is “.$students[3][1].”years old and study in “.$students[3][2].”.<br>”;
?>
Output :
Joe is 14 years old and study in 9.
John is 15 years old and study in 10.
For more about multidimensional and looping we shall discuss in next topic :
Follow the links for multidimensional : http://phpinterviewquestions.evernews.online/2018/02/what-is-multidimensional-arrays-in-php.html