What is the recommended method for writing the contents of an array to a file in PHP?

To write the contents of an array to a file in PHP, you can use the `file_put_contents()` function. This function allows you to write data to a file in a simple and efficient way. You can serialize the array using `serialize()` function before writing it to the file, so you can easily retrieve the array later by unserializing it using `unserialize()` function.

<?php
$array = [1, 2, 3, 4, 5];
$file = 'array_data.txt';

// Serialize the array
$data = serialize($array);

// Write the serialized array to a file
file_put_contents($file, $data);
?>