What is the purpose of file_get_contents() and how does it differ from file() in PHP?
file_get_contents() is a function in PHP that reads a file into a string. It is commonly used to retrieve the contents of a file and store it in a variable for further processing. On the other hand, file() reads a file into an array, where each element of the array corresponds to a line in the file. The choice between file_get_contents() and file() depends on whether you need the file contents as a string or an array.
// Using file_get_contents() to read a file into a string
$fileContents = file_get_contents('example.txt');
echo $fileContents;
// Using file() to read a file into an array
$fileLines = file('example.txt');
foreach ($fileLines as $line) {
echo $line;
}