Question:Consider the following script. What will the file myfile.txt contain at the end of its execution?<?php
$array = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$f = fopen ("myfile.txt", "r");
for ($i = 0; $i < 50; $i++) {
fwrite ($f, $array[rand(0, strlen ($array) - 1)]);
}
?>
A Nothing, because $array is not an actual array but a string.
B A random sequence of 49 characters.
C A random sequence of 50 characters.
D A random sequence of 41 characters.
E Nothing, or the file will not exist, and the script will output an error
+ ExplanationThe correct answer is E. Note how the file is being opened with the r parameter, which indicates that we want to use the file for reading. Therefore, if the file does not exist, PHP will output an error complaining that it cannot be found. If it does exist, the call to fopen() will be successful, but the subsequent fwrite() operations will fail due to the file having been opened in the wrong way. If we were to specify w instead of r, the script would run successfully and myfile.txt would contain a sequence of fifty random characters (remember that the characters of a string can be accessed as if they were elements of an array, just like in C).