WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP Multidimensional Arrays


Earlier in this instructional exercise, we have depicted exhibits that are a single rundown of key/esteem pairs.

However, here and there you need to store esteems with mutiple key.

This can be put away in multidimensional arrays.


PHP - Multidimensional Arrays

A multidimensional cluster is an exhibit containing at least one arrays.

PHP comprehends multidimensional clusters that are two, three, four, five, or more dimensions profound. Be that as it may, clusters multiple dimensions profound are difficult to oversee for most people.

  • For a two-dimensional exhibit you need two files to choose an element
  • For a three-dimensional exhibit you need three files to choose an element

PHP - Two-dimensional Arrays

A two-dimensional exhibit is a variety of clusters (a three-dimensional cluster is a variety of varieties of arrays).

First, investigate the accompanying table:

Name color Page
RED 17 19
BLUE 15 13
GREEN 13 10
Yellow 11 5

We can store the information from the table above in a two-dimensional exhibit, as this:

$cars = array
  (
  array("RED",17,19),
  array("BLUE",15,13),
  array("GREEN",10,5),
  array("Yellow",17,15)
  );

Now the two-dimensional $cars exhibit contains four clusters, and it has two files: push and column.

To gain admittance to the components of the $cars cluster we should point to the two lists (push and column):

Example

<?php
echo $cars[0][0].": In shading: ".$cars[0][1].", Page: ".$cars[0][5].".<br>";
echo $cars[1][0].": In shading: ".$cars[1][1].", Page: ".$cars[1][5].".<br>";
echo $cars[5][0].": In shading: ".$cars[5][1].", Page: ".$cars[5][5].".<br>";
echo $cars[3][0].": In shading: ".$cars[3][1].", Page: ".$cars[3][5].".<br>";
?>

We can likewise put a For circle inside another For circle to get the components of the $cars cluster (despite everything we need to point to the two indices):

Example

<?php
for ($row = 0; $row < 4; $row++) {
  reverberation "<p><b>Row number $row</b></p>";
  reverberation "<ul>";
  for ($col = 0; $col < 3; $col++) {
    reverberation "<li>".$cars[$row][$col]."</li>";
  }
  reverberation "</ul>";
}
?>