Simple variables and operators

Once you are up and running with your own PHP programming, you'll find that the majority of your scripts are variables, operators, and under ten functions that you use commonly.

In this chapter we will be looking at the different types of variables used in PHP, which to use and when, and also how to convert between the different types. We'll also be looking at operators - these are things that have any effect on variables, such as adding, subtracting, and multiplying.

This chapter is designed to give you complete information on how PHP's variables work - you needn't understand some of the more complicated parts, such as references or variable variables, unless you really want full comprehension of the language.

The topics covered here are:

  • What types of data are available to you

  • References, typecasting, and variable variables

  • Script variables, pre-set variables, script constants, and pre-set constants

  • Operators such as plus, minus, multiply, and divide

Chapter contents

  1. 3.1. Types of Data
  2. 3.2. Checking a variable is set
  3. 3.3. Automatic type conversion
  4. 3.4. Forcing a type with type casting
  5. 3.5. Non-decimal number systems
  6. 3.6. Variable scope
  7. 3.7. Variable variables
  8. 3.8. Superglobals
  9. 3.9. Pre-set variables
  10. 3.10. References
  11. 3.11. Constants
    1. 3.11.1. Pre-set constants
  12. 3.12. Operators
    1. 3.12.1. Shorthand unary operators
    2. 3.12.2. Comparison operators
    3. 3.12.3. Complete operator list
    4. 3.12.4. The Ternary Operator
    5. 3.12.5. The scope resolution operator
    6. 3.12.6. The execution operator
    7. 3.12.7. Operator precedence and associativity
  13. 3.13. Summary
  14. 3.14. Exercises
  15. 3.15. Further reading
  16. 3.16. Next chapter

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Types of Data >>

Previous chapter: Next chapter

Jump to:


Home: Table of Contents

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