Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
Multidimensional Arrays
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. PHP Tutorials
  3. Multidimensional Arrays

PHP Tutorial

Basic PHP Fundamentals

  • PHP Tutorial Content
  • PHP Introduction
  • PHP History
  • Uses of PHP
  • PHP Features
  • What Is PHP
  • PHP Installation And Software Requirements
  • How To Install Wamp Server
  • How To Install Xampp Server
  • Php Syntax
  • PHP Variables
  • PHP Data Types
  • PHP Constants
  • PHP Echo And Print
  • PHP Operators
  • PHP Assignment Operators
  • PHP String And Logical Operators
  • Operators Categories
  • PHP Comments
  • PHP $ And $$ Variables
  • Super Global Variables

PHP Control Statement

  • PHP Control Structure
  • PHP If Statement
  • If Elseif Statement In PHP
  • Switch Statement In PHP
  • Break Statement In PHP
  • If Elseif Else Statement
  • Continue Statement In PHP

Php Loops

  • What Is Loop
  • For Loop In PHP
  • PHP Foreach Loop
  • PHP While Loop
  • Do While Loop

PHP Arrays

  • PHP Arrays
  • Indexed Arrays
  • Associative Array
  • Multidimensional Arrays
  • Array Functions
  • Array Constants
  • List of Array Functions
  • Array Functions First Exercise

Php String

  • String In PHP
  • PHP String Functions

PHP Functions

  • PHP Functions
  • PHP Parameterized Function
  • PHP Call By Value
  • Call By Reference In PHP
  • Default Argument Values Function In PHP
  • Variable Argument Function In PHP
  • Recursive Function In PHP
  • Math Function In PHP
  • Math Function Examples

PHP Form

  • Form Handling In PHP

PHP Include

  • Include File In PHP

PHP State Management

  • Cookies In PHP
  • Session In PHP

PHP File System

  • File Handling In PHP
  • Open Files In PHP
  • Read Files In PHP
  • Write Files In PHP
  • Delete Files In PHP
  • Append To Files In PHP

PHP Upload & Download

  • File Upload In PHP
  • Download File In PHP

PHP Mail System

  • Mail System In PHP
  • Mail With Attachment In PHP

Basic PHP Program

  • Php Programs
  • Sum Of Digits
  • PHP Even Odd Program
  • Prime Number Program
  • Table Of Number Program
  • Factorial Of A Number
  • Armstrong Number
  • Palindrome Number
  • Fibonacci Series

Multidimensional Arrays

PHP Multidimensional array is also known as an array of arrays. It allows you to store tabular data in an array. PHP multidimensional array can be represented in the form of a matrix which is represented by row * column.

  • A multidimensional array is an array containing one or more arrays.
  • PHP understands multidimensional arrays that are two, three, four, five, or more levels deep. However, arrays more than three levels deep are hard to manage for most people.
  • The dimension of an array indicates the number of indices you need to select an element.

Type Of Multidimensional Array

  • Two-Dimensional Array: For a two-dimensional array you need two indices to select an element
  • Three-Dimensional Array: For a three-dimensional array you need three indices to select an element


PHP - Two-dimensional Arrays

A two-dimensional array is an array of arrays (a three-dimensional array is an array of arrays).

First, take a look at the following table:

Name Stock Sold
Cake 29 32
Pizza 99 59
Tea 25 2
Coffee 65 15

We can store the data from the table above in a two-dimensional array, like this:

$foods = array
  (
  array("Pizza",99,59),
  array("Cakes",29,32),
  array("Tea",25,2),
  array("Coffee",65,15)
  );


Now the two-dimensional $foods array contains four arrays, and it has two indices: row and column.

To get access to the elements of the $foods array we must point to the two indices (row and column):

Example

<?php
$foods = array
  (
  array("Pizza",99,59),
  array("Cakes",29,32),
  array("Tea",25,2),
  array("Coffee",65,15)
  );
echo $foods[0][0].": In stock: ".$foods[0][1].", sold: ".$foods[0][2].".<br>";
echo $foods[1][0].": In stock: ".$foods[1][1].", sold: ".$foods[1][2].".<br>";
echo $foods[2][0].": In stock: ".$foods[2][1].", sold: ".$foods[2][2].".<br>";
echo $foods[3][0].": In stock: ".$foods[3][1].", sold: ".$foods[3][2].".<br>";
?>

Output :

Pizza: In stock: 99, sold: 59.
Cakes: In stock: 29, sold: 32.
Tea: In stock: 25, sold: 2.
Coffee: In stock: 65, sold: 15.

We can also put a For loop inside another For loop to get the elements of the $cars array (we still have to point to the two indices):

Example 1:filename1.php

<?php
$foods = array
  (
  array("Pizza",99,59),
  array("Cakes",29,32),
  array("Tea",25,2),
  array("Coffee",65,15)
  );
    
for ($row = 0; $row < 4; $row++) {
  echo "<p><b>Food Stock $row</b></p>";
  echo "<ul>";
  for ($col = 0; $col < 3; $col++) {
    echo "<li>".$foods[$row][$col]."</li>";
  }
  echo "</ul>";
}
?>

Output:

Food Stock 0
Pizza
99
59
Food Stock 1
Cakes
29
32
Food Stock 2
Tea
25
2
Food Stock 3
Coffee
65
15
Series: PHP Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
Php Multidimensional Arrays Multidimensional Arrays php array array type of array Two-Dimensional Array php multidimensional array foreach php multidimensional associative array

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.