How can a two-dimensional array be created in PHP with one index representing column names and the other index representing row IDs?

To create a two-dimensional array in PHP with one index representing column names and the other index representing row IDs, you can use an associative array where the keys represent the column names and the values are arrays containing the row data. This allows you to access elements in the array using both column names and row IDs.

// Create a two-dimensional array with column names and row IDs
$twoDimArray = array(
    'column1' => array('row1' => 'value1', 'row2' => 'value2'),
    'column2' => array('row1' => 'value3', 'row2' => 'value4')
);

// Accessing elements in the two-dimensional array
echo $twoDimArray['column1']['row1']; // Output: value1
echo $twoDimArray['column2']['row2']; // Output: value4