How can print_r() be used effectively within a loop to debug PHP code when working with MySQL inserts?

When working with MySQL inserts in PHP, it can be helpful to use print_r() within a loop to debug the data being inserted. By printing out the data at each iteration of the loop, you can easily identify any issues with the data or the loop itself. This can help you pinpoint any errors and troubleshoot your code effectively.

// Sample code demonstrating the use of print_r() within a loop for debugging MySQL inserts

// Assuming $data is an array containing the data to be inserted
foreach ($data as $row) {
    print_r($row); // Print out the data being inserted for debugging
    // Perform MySQL insert query using $row data
}