Answers to Chapter 3

  1. "Which of the following are not valid variables", the answer is "d" - variables may not start with a number.

  2. "What will $foo be set to in this expression: $foo = "wombat" * 2 The answer is 0, because a string multiplied by an integer will yield 0.

  3. "What will $bar be set to in this expression: $bar = 5 * 5 + 5 The answer is 30, because multiplication takes precedence over addition, meaning that the 5 * 5 is done first, giving 25, then 5 is added, giving 30.

  4. "What does the =< operator do?" The answer is: terminate PHP. This is because there is a <= operator meaning "less than or equal to", but there is no =< operator, so PHP will exit saying, "parse error, unexpected '<'. Trick question - sorry!

  5. "How does OR different from ||" - || is a higher priority operator than OR, meaning it gets evaluated sooner.

  6. "The superglobal array variables are accessible..." can be answered only by "e". Well, if you were listening, that is!


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 4 >>

Previous chapter: Answers to Chapter 2

Jump to:


Home: Table of Contents

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