"How many times should srand() be called" The answer is "b": calling it more or less than once per script will affect the randomness.
"To safely pass an array over the web, what is the correct sequence of function calls" You should really be looking for "d".
"When passing a negative "step" parameter to the range() function, the initial value must always be larger than the end value: true or false" Another trick question - I do apologise! You can't specify a negative step parameter.
"To randomise the order of an array, which function(s) can you use" The answer is "a": shuffle().
"Which of the following statements are true about arrays that have a hole" The answer is "a": use foreach. You might have thought "b" was correct, but array_values() irretrievably destroys the existing keys, which is often a bad thing!
Want to learn PHP 7?
Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!
If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!
Next chapter: Answers to Chapter 6 >>
Previous chapter: Answers to Chapter 4
Home: Table of Contents
Copyright ©2015 Paul Hudson. Follow me: @twostraws.