What are some best practices for efficiently combining array elements to generate multiple INSERT INTO statements in PHP without using recursion?

To efficiently combine array elements to generate multiple INSERT INTO statements in PHP without using recursion, you can use a loop to iterate through the array and concatenate the values into the INSERT INTO statement. This allows you to insert multiple rows into a database table in a single query, improving performance.

// Sample array of data
$data = [
    ['John', 'Doe', 30],
    ['Jane', 'Smith', 25],
    ['Mike', 'Johnson', 35]
];

// Generate INSERT INTO statements
$insertValues = [];
foreach ($data as $row) {
    $insertValues[] = "('" . implode("', '", $row) . "')";
}

$insertQuery = "INSERT INTO table_name (first_name, last_name, age) VALUES " . implode(", ", $insertValues);

// Execute the query using your database connection
// mysqli_query($conn, $insertQuery);