To read a file into an array, which of the following function can be used?
-
file_read()
-
file()
-
read()
-
array()
The file() function reads a file into an array where each element corresponds to a line in the file. file_read() and read() are not standard PHP file-reading functions, and array() is a language construct for creating arrays, not reading files.
In PHP, the file() function reads an entire file into an array, with each element corresponding to one line of the file (including the newline, unless a flag like FILE_IGNORE_NEW_LINES is passed). This matches the correct answer. file_read() is not a real PHP function. read() is not a standalone PHP function for file reading either (PHP uses fread(), fgets(), etc.). array() is simply the language construct/function for creating an array — it doesn't read files at all. Only file() reads file contents directly into an array structure.