What are some best practices for handling multi-dimensional arrays in PHP when using INSERT INTO statements?

When handling multi-dimensional arrays in PHP for INSERT INTO statements, it is important to loop through the outer array and then bind and execute the INSERT statement for each inner array. This ensures that each inner array is inserted as a separate row in the database table.

<?php

// Assuming $multiDimArray is the multi-dimensional array to be inserted
foreach ($multiDimArray as $innerArray) {
    $stmt = $pdo->prepare("INSERT INTO table_name (column1, column2) VALUES (?, ?)");
    $stmt->bindParam(1, $innerArray['value1']);
    $stmt->bindParam(2, $innerArray['value2']);
    $stmt->execute();
}

?>