How can a multiple insert operation be performed in PHP for inserting data into a table?

To perform a multiple insert operation in PHP for inserting data into a table, you can use a loop to iterate over an array of data and execute individual insert queries for each set of values. This allows you to efficiently insert multiple rows of data into the table in a single operation.

// Sample array of data to be inserted
$data = [
    ['John', 'Doe'],
    ['Jane', 'Smith'],
    ['Alice', 'Johnson']
];

// Connect to the database
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// Prepare the insert query
$stmt = $pdo->prepare("INSERT INTO users (first_name, last_name) VALUES (?, ?)");

// Iterate over the array and execute insert queries
foreach ($data as $row) {
    $stmt->execute($row);
}