PHP MySQL  Tutorial-8- Multidimensional Arrays Part 2

Hosted by Dailymotion. For legal issues report at the Copyright Center, report us on DMC, or use the Instant Removal tool.

PHP MySQL Tutorial-8- Multidimensional Arrays Part 2

W
WEB Development Trainer

6 Views • Apr 20, 2018

Description

In PHP, two-dimensional arrays are arrays that contain arrays/ array with in array. You can think of the outer array as containing the rows and the inner arrays as containing the data cells in those rows. For example, a two-dimensional array called $foods could contain the names of the HEALTHY and UNHEALTHY foods. Below is a grid that represents such a two-dimensional array.

Healthy Foods: Unhealthy Foods:
Salad Ice Cream
Vegetables Pizza
Pasta


To read an element from a two-dimensional array, you must first identify the index of the "row" and then identify the index of the "column." For example, the song "Angie" is in row 1, column 2, so it is identified as $foods[‘Healthy’][1]. Or $foods[‘Healthy’][2].
Remember that the first row is row 0 and the first column is column 0.

For accessing all elements of multidimensional array, we use for each construct.