Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

CHAPTER 10: Working with Variables

CHAPTER 10

Working with Variables

Variables are an important part of any programming language, and that goes for PHP too. Variables are blocks of memory associated with a name and a data type, and variables contain data to be used in calculations, program flow, presentation, and so on.

PHP is a loosely typed language where variables can be used without declarations and where they can change type from line to line, in some cases without losing the content. This makes programming much easier than in more strictly typed languages, but it can also make it more difficult to debug the code.

All variable names in PHP start with a dollar ($) sign. This makes it easy for the scripting engine, as well as the reader, to identify variables anywhere in the code, including when they are embedded in strings. Also, using the $ sign allows the developer to use variable names that would otherwise be reserved by the engine for function names and language constructs. This means writing code where function names are used as variable names, such as $strlen = strlen("This is a test");, is allowed.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


 Â