8. What will the following script output?

<?php
$array = 0123456789ABCDEFG ;
$s = ;
for ($i = 1; $i < 50; $i++) {
$s .= $array[rand(0,strlen ($array) - 1)];
}
echo $s;
?>


Вариант ответа 1 - A) A string of 50 random characters

Вариант ответа 2 - B) A string of 49 copies of the same character, because the random number generator has not been initialized

Вариант ответа 3 - C) A string of 49 random characters

Вариант ответа 4 - D) Nothing, because $array is not an array

Вариант ответа 5 - E) A string of 49 ‘G’ characters


Комментарий: The correct answer is C. As of PHP, there is no need to initialize the random number generator using srand() unless a specific sequence of pseudorandom numbers is sought. Besides, even if the random number generator had not been seeded, the script would have still outputted 49 pseudo-random characters—the same ones every time. The $array variable, though a string, can be accessed as an array, in which case the individual characters corresponding to the numeric index used will be returned. Finally, the for loop starts from 1 and continues until $i is less than 50—for a total of 49 times.

Комментарии

Имя пользователяТекст комментарияВведите код