Exercises

  1. What is the difference between an associative array and a multidimensional array?

  2. How many times should srand() be called?

    • a) Once ever

    • b) Once per script

    • c) Once for every call to shuffle(), before the call

    • d) Once for every call to shuffle(), after the call

  3. To safely pass an array over the web, what is the correct sequence of function calls:

    • a) urlencode(), serialize(), unserialize(), urldecode()

    • b) urldecode(), unserialize(), serialize(), urlencode()

    • c) serialize(), unserialize(), urlencode(), urldecode()

    • d) serialize(), urlencode(), urldecode(), unserialize()

  4. When passing a negative "step" parameter to the range() function, the initial value must always be larger than the end value: true or false?

  5. To randomise the order of an array, which function(s) can you use:

    • a) shuffle()

    • b) mt_shuffle()

    • c) Both of the above

    • d) Neither a) nor b)

  6. Which of the following statements are true about arrays that have a hole (e.g. it has keys 0, 1, 2, and 4):

    • a) You can use foreach to loop through the array and ignore the hole

    • b) You can use the array_values() function to re-order the keys

    • c) You can use the arsort() function to re-order the keys

    • d) All of the above

 

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: Further reading >>

Previous chapter: Summary

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.