How can a for loop be effectively utilized in PHP to achieve the desired result of inserting duplicate entries into a MySQL database?

To insert duplicate entries into a MySQL database using a for loop in PHP, you can create an array of values to be inserted and then loop through that array to execute the insert query multiple times. This can be useful in scenarios where you need to quickly populate a database table with repeated data for testing or demonstration purposes.

<?php
// Connect to MySQL database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Array of values to be inserted
$values = ["value1", "value2", "value3"];

// Loop through the array and insert values into the database
foreach ($values as $value) {
    $query = "INSERT INTO table_name (column_name) VALUES ('$value')";
    mysqli_query($connection, $query);
}

// Close database connection
mysqli_close($connection);
?>