PHP 5 for Dummies Free Open Book

PHP 5 for Dummies

Previous PageNext Page
Chapter 4
Using Variables in PHP Scripts
In This Chapter
Naming variables
Assigning values to variables
Removing variables
Using constants
Handling errors
V
ariablesare containers that hold information. First, you give a variable a
name, and then you can store information in it. For example, you could
name a variable 
$age
and store the number 21 in it. After you store informa-
tion in a variable, you can use that variable later in the script. 
When using PHP on the Web, variables are often used to store the informa-
tion that users type into an HTML form, such as their names. You can then
use the variable later in the script, perhaps to personalize a Web page by dis-
playing the user’s name, as in, for example, 
Welcome Sam Smith
In this chapter, you find out how to create variables, name them, and store
information in them. You also discover how to handle errors.
Naming Variables
Variable names or identifiersshould be very descriptive. I have seen scripts
where all the variables were named 
$var1
$var1
$var2
, and so on. It may
seem straightforward to name variables like this, but two years from now
when you come back to the script, it will take forever to figure out what
information is in each variable. PHP won’t care or get confused, but humans
trying to follow the script will have a hard time. Make your scripts much
easier to understand by using descriptive variable names like 
$firstName
,
$directory_name
, or 
$DateOfBirth
.
Previous PageNext Page


     Main Menu
PHP 5 for Dummies
Table of Contents
Introduction
Part I: Say Hello to the PHP Scripting Language
Part II: Variables and Data
Documenting the Script - Page 68
Documenting the Script - Page 69
Chapter 4: Using Variables in PHP Scripts
Assigning and Displaying Variable Values
Writing Your First Script That Uses Variables
Discovering More about Output Statements with Variables
Using Variable Variables
Removing Variables
Working with Constants
Handling Error Messages
Chapter 5: Working with Data
Chapter 6: Storing Data in Groups by Using Arrays
Part III: Basic PHP Programming
Part IV: Common PHP Applications
Part V: The Part of Tens
Part VI: Appendixes
Index
Team DDU


More Books
PHP Hacks
Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
The Koran (Holy Qur'an)
Macromedia Flash 8 Bible
Search Engine Optimization for Dummies
YouTube Traffic
PHP 5 for Dummies
Harry Potter and The Chamber of Secrets
Harry Potter and the Sorcerer's Stone
The Pilgrim's Progress
Wireless Hacks
Flash Hacks. 100 Industrial-Strength Tips & Tools
PayPal Hacks. 100 Industrial-Strength Tips and Tools
Amazon Hacks
Pdf Hacks
The Da Vinci Code
Google Hacks
The Holy Bible
Windows XP For Dummies
Harry Potter and the Half-Blood Prince
Seo Book
Upgrading and Repairing Networks
Macromedia Dreamweaver 8 UNLEASHED
Windows XP Annoyances
Windows XP Hacks
Microsoft Windows XP Power Toolkit
Teach Yourself MS Office In 24Hours
iPod & iTunes Missing Manual
PC Hacks 100 Industrial-Strength Tips and Tools
PC Overclocking, Optimization, and Tuning - 2th Edition
PC Hardware In A Nutshell 3rd Edition
PC Hardware in a Nutshell, 2nd Edition
Upgrading and Repairing PCs
Google for Dummies
MySQL Cookbook
Teach Yourself Macromedia Flash 8 In 24 Hours
PHP CookBook
Sams Teach Yourself JavaScript in 24 Hours
PHP5 Manual
Free Games Paper Airplanes
500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele