Are there any potential pitfalls when using mysql_fetch_assoc to create a multidimensional array in PHP?

When using mysql_fetch_assoc to create a multidimensional array in PHP, one potential pitfall is that it may not handle nested arrays properly, resulting in unexpected behavior or data loss. To avoid this issue, you can fetch the rows as associative arrays and then manually build the multidimensional array using a loop.

// Fetch rows as associative arrays
$result = mysql_query("SELECT * FROM table");
$rows = [];
while ($row = mysql_fetch_assoc($result)) {
    $rows[] = $row;
}

// Build multidimensional array
$multiArray = [];
foreach ($rows as $row) {
    $multiArray[$row['key']] = $row;
}