How can you format the output of MySQL query results in PHP to remove trailing commas?

When querying data from a MySQL database in PHP and outputting the results, you may encounter an issue where the output contains trailing commas at the end of each line. This can be undesirable, especially when working with arrays or lists. To remove these trailing commas, you can use the `implode()` function in PHP to join the elements of the array without adding a comma at the end.

// Sample MySQL query result
$queryResult = ['item1', 'item2', 'item3', 'item4'];

// Remove trailing commas by using implode function
$output = implode(', ', $queryResult);

// Output the formatted result
echo $output;