Skip to Content
Learning PHP, MySQL, JavaScript, and CSS, 2nd Edition
book

Learning PHP, MySQL, JavaScript, and CSS, 2nd Edition

by Robin Nixon
August 2012
Beginner
583 pages
16h 1m
English
O'Reilly Media, Inc.
Content preview from Learning PHP, MySQL, JavaScript, and CSS, 2nd Edition

Chapter 3 Answers

  1. The tag used to start PHP interpreting code is <?php ... ?>, which can be shortened to <? ... ?>.

  2. You can use // for a single-line comment or /* ... */ to span multiple lines.

  3. All PHP statements must end with a semicolon (;).

  4. With the exception of constants, all PHP variables must begin with $.

  5. A variable holds a value that can be a string, a number, or other data.

  6. $variable = 1 is an assignment statement, whereas $variable == 1 is a comparison operator. Use $variable = 1 to set the value of $variable. Use $variable == 1 to find out later in the program whether $variable equals 1. If you mistakenly use $variable = 1 where you meant to do a comparison, it will do two things you probably don’t want: set $variable to 1 and return a true value all the time, no matter what its previous value was.

  7. A hyphen is reserved for the subtraction operators. A construct like $current-user would be harder to interpret if hyphens were also allowed in variable names and, in any case, would lead programs to be ambiguous.

  8. Variable names are case-sensitive. $This_Variable is not the same as $this_variable.

  9. You cannot use spaces in variable names, as this would confuse the PHP parser. Instead, try using the _ (underscore).

  10. To convert one variable type to another, reference it and PHP will automatically convert it for you.

  11. There is no difference between ++$j and $j++ unless the value of $j is being tested, assigned to another variable, or passed as a parameter to a function. In such cases, ++$j ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning PHP, MySQL & JavaScript, 4th Edition

Learning PHP, MySQL & JavaScript, 4th Edition

Robin Nixon

Publisher Resources

ISBN: 9781449337452Errata Page