11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 3 • <strong>PHP</strong> BASICSConverting TypesThe settype() function converts a variable to the type specified by type. Seven possible type values areavailable: array, boolean, float, integer, null, object, and string. If the conversion is successful, TRUE isreturned; otherwise, FALSE is returned. Its prototype follows:boolean settype(mixed var, string type)Type Identifier FunctionsA number of functions are available for determining a variable’s type, including is_array(), is_bool(),is_float(), is_integer(), is_null(), is_numeric(), is_object(), is_resource(), is_scalar(),and is_string(). Because all of these functions follow the same naming convention, arguments, andreturn values, their introduction is consolidated into a single example. The generalized prototypefollows:boolean is_name(mixed var)All of these functions are grouped in this section because each ultimately accomplishes the sametask. Each determines whether a variable, specified by var, satisfies a particular condition specified bythe function name. If var is indeed of the type tested by the function name, TRUE is returned; otherwise,FALSE is returned. An example follows:This code returns the following:The variable $item is of type array: 0The variable $item is of type integer: 1The variable $item is numeric: 1You might be wondering about the backslash preceding $item. Given the dollar sign’s specialpurpose of identifying a variable, there must be a way to tell the interpreter to treat it as a normalcharacter should you want to output it to the screen. Delimiting the dollar sign with a backslash willaccomplish this.IdentifiersIdentifier is a general term applied to variables, functions, and various other user-defined objects. Thereare several properties that <strong>PHP</strong> identifiers must abide by:55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!