What is the difference between using mysql_fetch_array and a custom function for array retrieval in PHP?

The main difference between using mysql_fetch_array and a custom function for array retrieval in PHP is that mysql_fetch_array is a built-in function specifically designed to fetch rows from a MySQL result set as an associative array, while a custom function can be created to handle array retrieval in a more customizable way. Using mysql_fetch_array is quicker and easier for simple tasks, but a custom function allows for more flexibility and control over how the array is retrieved and processed.

// Using mysql_fetch_array
$result = mysql_query("SELECT * FROM table");
while ($row = mysql_fetch_array($result)) {
    // Process each row as an associative array
}

// Using a custom function for array retrieval
function fetchCustomArray($result) {
    $rows = array();
    while ($row = mysql_fetch_assoc($result)) {
        $rows[] = $row;
    }
    return $rows;
}

$result = mysql_query("SELECT * FROM table");
$rows = fetchCustomArray($result);
foreach ($rows as $row) {
    // Process each row as an associative array
}