spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / php / by_example

[previous]

Finance Developer (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume
Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans


The Building Blocks:
Data Types, Literals, Variables, and Constants

Boolean Literals

Boolean literals (introduced in PHP 4) are logical values that have only one of two values, true or false, both case insensitive. You can think of the values as yes or no, on or off, or 1 or 0. They are used to test whether a condition is true or false. When using numeric comparison and equality operators, the value true evaluates to 1 and false evaluates to the empty string (see Figure 4.8).

Example 4.6

Figure 4.8 True and false.

Special Data Types

Null. NULL represents "no value," meaning "nothing," not even an empty string or zero. It is a type of NULL. An uninitialized variable contains the value NULL. A variable can be assigned the value NULL, and if a variable has been unset, it is considered to be NULL.

Resource. A resource is a special variable, holding a reference to an external resource such as a database object or file handler. Resources are created and used by special functions. File and database resources are defined by the PHP interpreter and are only accessible by functions provided by the interpreter (see Chapter 11, "Files and Directories," and Chapter 15, "PHP and MySQL Integration).

The gettype() Function. The gettype() built-in function returns a string to identify the data type of its argument. The argument might be a variable, string, keyword, and so on. You can use the gettype() function to check whether or not a variable has been defined because if there is no value associated with the variable, the gettype() function returns NULL (see Figure 4.9).

Strings returned from the gettype() function include the following:

  • boolean (since PHP 4)
  • integer
  • double (for historical reasons double is returned in case of a float, and not simply float)
  • string
  • array
  • object
  • resource (since PHP 4)
  • NULL (since PHP 4)

Format

string gettype ( mixed var )

Examples:

Example 4.7

Figure 4.9 PHP data types. Output from Example 4.7.

This chapter is excerpted from the book titled, PHP and MySQL by Example, authored by Ellie Quigley. Copyright 2007 Pearson Education, Inc., published by Prentice Hall Professional, November, 2006. ISBN 0131875086.
home / programming / php / by_example

[previous]


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger

URL: