What role does the mysql_fetch_array() function play in retrieving records from a table in PHP?

The mysql_fetch_array() function is used to retrieve a single row of data from a MySQL database table as an associative array or numerical array. This function is commonly used in PHP to fetch records from a database query result. It allows you to access the data in the fetched row by column name or index.

// Connect to the database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Execute a query
$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);

// Fetch a row from the query result
$row = mysqli_fetch_array($result);

// Access data from the fetched row
echo $row['column_name']; // Access by column name
echo $row[0]; // Access by index