Page 71 - Beginning PHP 5.3
P. 71
3
PHP Language Basics
So far you ’ ve looked at what PHP is, and what you can use it for. You ’ ve also written and tested a
simple PHP script to give you a feel for how the language works. Now, in these next few chapters,
you ’ ll build a solid foundation of knowledge that you can use to create more complex applications
and Web sites in PHP.
This chapter gets the ball rolling. In it you explore some of the fundamental concepts of PHP — its
building blocks, if you will. You learn about:
❑ Variables , which let you store and manipulate data in your scripts
❑ Data types , including which types are available in PHP, and how to test for and
change type
❑ PHP ’ s available operators , which you can use to manipulate information
❑ Constants , which are useful for storing data that doesn ’ t change in your script
These are all important concepts, both in PHP and in other programming languages. Once you ’ ve
read and digested this chapter, you ’ ll be ready to move on and tackle the other features of the PHP
language.
Using Variables in PHP
Variables are a fundamental part of any programming language. A variable is simply a container
that holds a certain value. Variables get their name because that certain value can change
throughout the execution of the script. It ’ s this ability to contain changing values that make
variables so useful.
For example, consider the following simple PHP script:
echo 2 + 2;
9/21/09 8:51:20 AM
c03.indd 33 9/21/09 8:51:20 AM
c03.indd 33