Can someone provide a sample code snippet demonstrating how to efficiently edit and update specific lines in a .txt database using PHP arrays and file handling functions?

To efficiently edit and update specific lines in a .txt database using PHP arrays and file handling functions, you can read the file into an array, make the necessary changes to the specific line in the array, and then write the updated array back to the file.

<?php
// Read the file into an array
$lines = file('database.txt');

// Update the specific line (e.g., line 3)
$lines[2] = "Updated data for line 3\n";

// Write the updated array back to the file
file_put_contents('database.txt', implode('', $lines));
?>