How can arrays be created and written to a database in PHP?

To create an array in PHP, you can simply declare it using the array() function or using square brackets []. To write an array to a database in PHP, you can use SQL queries to insert the array values into the database table. You can loop through the array and construct an SQL query to insert each array element into the database.

<?php
// Create an array
$data = array('John', 'Doe', 'john.doe@example.com');

// Connect to the database
$connection = mysqli_connect('localhost', 'username', 'password', 'database');

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

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