Although variables are not declared to be type-specific in PHP,
PHP still has a common set of data types:boolean integer float string array object resource NULLDetermining the current type of a variable: A series of type-testing functions exist to determine the current type of variables: gettype(varname)returns type name, such as 'string' is_int() is_integer() is_long() is_null() is_numeric() is_object() is_real() is_string() is_scalar() is_bool() empty() isset()PHP type comparison tables Special debugging / variable-display functions: print_r() var_dump() var_export() Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed as: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' To assign values or expressions to variables, the standard assignment equal-sign operator ( = ) is used
|
Special Relationship Between Strings and Variables
String constants can be defined in one of three common ways: Inside Single Quotes: 'One type of string' Inside Double Quotes: "Another type of string" Using special "heredoc" syntax (discussed later) Data inside Single-quoted strings are taken literally; ie., everything is treated exactly as it is typed Data inside Double-quoted strings are treated in a special way in relationship to variable references and other standard formatting characters: If a variable is referenced inside a double-quoted string, its value is automatically substituted. "Escaped" characters are interpreted: Table of "Escaped" characters
All string constants (single- or double-quoted) can be automatically continued onto multiple lines:
|
Displaying Values
Values can be displayed (output) using three methods:echo , print() , and printf() echo string arg1 [, string argn...]; echo outputs all values following it. It is not actually a
function (it is a language construct) so you are not required to use
parentheses with it.
print() is in some ways similar to echo ,
although it can be used as a function and could be included in more
complicated expressions
echo
and print printf() is one member of a family of string formatting
functions. It is based on the syntax of the sprintf()
function.
|
0 comments:
Post a Comment