Hudzilla.org - the homepage of Paul Hudson
Contents > Arrays Wish List | Report Bug | About Me ]

5.13     Exercises

This is NOT the latest copy of this book; click here for the latest version.

  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





<< 5.12 Summary   5.14 Further reading >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
A PHP abUser - 29 Aug 2008

That was a relatively straightforward and easy to follow chapter....Thanks!



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is four plus two?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow