Multidimensional Arrays in PHP

Last updated: August 27, 2026.

A multidimensional array contains arrays as values. Associative keys make records clearer than unexplained numeric positions.

<?php
declare(strict_types=1);
$products = [
    ['name' => 'Rose', 'price' => 1.25, 'stock' => 15],
    ['name' => 'Daisy', 'price' => 0.75, 'stock' => 25],
];
foreach ($products as $product) {
    printf("%s: %.2f (%d in stock)\n", $product['name'], $product['price'], $product['stock']);
}

Validate expected keys at application boundaries. For large relational datasets, fetch only the needed rows and columns. See the PHP array reference.

admin

admin

One thought on “Multidimensional Arrays in PHP”

Leave a Reply

Your email address will not be published. Required fields are marked *