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

3     Simple variables and operators

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

Once you are up and running with your own PHP programming, you will 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 need not 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

3.1. Types of Data
3.2. Checking a variable is set: isset()
3.3. Automatic type conversion
3.4. Forcing a type with type casting
3.5. Non-decimal number systems
3.6. Variable scope
3.7. Variable variables
3.8. Superglobals
3.9. Pre-set variables
3.10. References
3.11. Constants: define(), defined(), and constant()
3.11.1. Pre-set constants
3.12. Operators
3.12.1. Shorthand unary operators
3.12.2. Comparison operators
3.12.3. Complete operator list
3.12.4. The Ternary Operator
3.12.5. The scope resolution operator
3.12.6. The execution operator
3.12.7. Operator precedence and associativity
3.13. Summary
3.14. Exercises
3.15. Further reading
3.16. Next chapter



<< 2.12 Next chapter   3.1 Types of Data >>
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
khanasad24@yahoo.com - 04 Jul 2008

hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

Date-checker - 04 Jul 2008

This comment written on third July 2006

:< - 04 Jul 2008

What is the greatest difference between learning PHP and Swedish?

There´s no variables in Swedish.

:< - 04 Jul 2008

What is the greatest difference between learning PHP and Swedish?

There´s no variables in Swedish.

Utkarsh Sharma - 04 Jul 2008

Haven't seen Simplicity until i saw your website!

A very new PHP User - 04 Jul 2008

ok... i understand most of the earlier parts... so now on to 3!

I only know HTML... so i must admit, you are very good at teaching PHP...! Well done!

A PHP User - 04 Jul 2008

sadfasdf



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 three plus eight?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow