How can a two-dimensional array be a more efficient alternative to defining keys in an associative array using a loop in PHP?

Using a two-dimensional array can be more efficient than defining keys in an associative array using a loop in PHP because it allows for direct access to values without the need for iterating through keys. This can result in faster data retrieval and manipulation, especially when dealing with large datasets. Additionally, two-dimensional arrays can be easier to work with in certain situations where data is naturally structured in rows and columns.

// Using a two-dimensional array for storing data
$data = [
    [1, 'John', 25],
    [2, 'Alice', 30],
    [3, 'Bob', 22]
];

// Accessing data directly
echo $data[1][1]; // Output: Alice