Truth Table for the and Operator or Syntax variable1 or variable2 Description The or operator evaluates whether either variable1 or variable2 is true.. In understanding the truth tab
Trang 1Table 4.5 Truth Table for the and Operator
or
Syntax
variable1 or variable2
Description
The or operator evaluates whether either variable1 or variable2 is true Table 4.6
contains the truth table for the possible values In understanding the truth table, you can see the only time the equation returns false is when both variable1 and
variable2 are false
Note
The only difference between this operator and the || operator is order precedence
Table 4.6 Truth Table for the or Operator
xor
Syntax
variable1 xor variable2
Trang 2Description
The xor, or exclusive or operator, evaluates whether either variable1 and
variable2 , but not both, is true Table 4.7 contains the truth table for the possible values In understanding the truth table, you can see when variable1 and
variable2 are the same, false is returned
Table 4.7 Truth Table for the xor Operator
! (not)
Syntax
!variable
Description
The !, or not operator, returns the opposite of variable For instance, if variable
is true, applying the ! operator will return false
&& (and)
Syntax
variable1 && variable2
Description
The && operator evaluates whether variable1 and variable2 are true, or equal
Table 4.8 contains the truth table for the possible values In understanding the truth table, you can see the only time the equation returns true is when both variable1 and variable2 are true
Note
The only difference between this operator and the and operator is order precedence
Trang 3Table 4.8 Truth Table for && Operator
|| (or)
Syntax
variable1 || variable2
Description
The || operator evaluates whether either variable1 or variable2 is true Table 4.9
contains the truth table for the possible values In understanding the truth table, you can see the only time the equation returns false is when both variable1 and
variable2 are false
Note
The only difference between this operator and the or operator is order precedence
Table 4.9 Truth Table for the || Operator
String
The string operators are used to perform manipulation on the string data types Although some of the previous operators discussed in this section can be performed
on strings as well, these are limited to strings only
Trang 4Syntax
string1 string2
Description
The ., or concatenation operator, will "add" string2 to string1 when applied For
instance, if string1 ="P" and string2 ="HP", string1 string2 would equal
"PHP"
$string1 = "hel";
$string2 = "p";
$string3 = "lo";
$result1 = $sting1 $string2; // $result1 has "help"
$result2 = $sting1 $string3; // $result2 has "hello"
.= (Concatenating Assignment)
Syntax
string1 = string2
Description
The , or concatenating assignment operator, will "add" string2 to string1 when
applied and then store the new string in string1 For instance, if string1 ="P" and
string2 ="HP", then string1 = string2 would equal "PHP" and that would be the new value of string1
Predefined Variables
Predefined variables in PHP refer to language elements that are consistent across all applications run in that environment This is very much like the environment variables you see within the UNIX and Windows operating systems (Type env at a command line to see a list of your operating system variables.)
Apache
The Apache predefined variables reflect the environment settings of your Apache Web server when running PHP There are also variables that reflect information about a request of a given user-agent, or browser This enables you to grab the requested URL, query string, or another element of the HTTP request
Trang 5DOCUMENT_ROOT
Syntax
string DOCUMENT_ROOT
Description
The DOCUMENT_ROOT variable contains the document root, as defined in the PHP configuration file, under which the current script is being parsed
GATEWAY_INTERFACE
Syntax
string GATEWAY_INTERFACE
Description
The GATEWAY_INTERFACE variable contains the version of the Common Gateway Interface (CGI) specification that the server is using For instance, CGI/1.1 is a valid GATEWAY_INTERFACE
HTTP_ACCEPT
Syntax
string HTTP_ACCEPT
Description
The HTTP_ACCEPT variable contains the contents of the HTTP Accept: header if the user-agent sent it to the server
HTTP_ACCEPT_CHARSET
Syntax
string HTTP_ACCEPT_CHARSET