Chapter Three Basics of PHP
(3.6--3.11)
3.6 variables
Variable declaration
Variable assignment: Assign value by value/reference assignment
Variable scope:
Local variable: A variable declared in a function that can only be referenced in a function
Function arguments: Any function that accepts parameters must declare them at the first part of the functions. Although these parameters accept values outside the function, they are no longer accessible after exiting the function
Parameter instance
// multiplies a value by 10 and returns it to the caller function x10 ($value) { $value$value *; return $value ;} // after the function is executed, the parameters are revoked .
Global variables: (Use caution)
When accessing inside a function, simply precede the variable with the keyword global
Another way is to use PHP's $globals array. $GLOBALS [""];
Static variables:
Unlike a variable declared as a function parameter, a function parameter is revoked when the function exits, and the static variable does not lose value when the function exits, and it can also save the value to use when calling the function again.
A static variable can be declared by adding the keyword static before the variable name
PHP's Super Global variables:
Detailed information about the current user session, user operating environment, and local operating environment can be obtained via PHP's super global variables
foreach ($_serveras$var$value) { echo "$var$value
";} // For example, display the User IP address: printf ("Your IP address is:%s",$_server[' REMOTE_ADDR ']); // You can also get information about your user's browser and operating system: printf ("Your browser is:%s",$_server[' http_user-agent ']);
gives all predefined variable codes related to a given Web server and script execution Environment
Get the passed variable with the Get method
Use the Post method to get the passed variable
Get the information stored in the cookie:
$_cookie Super Global variable stores information passed to the script via an HTTP cookie
These cookies are typically set by PHP functions Setcookie () by a previously executed PHP script.
Get information about uploading files using the Post method
$_files Super Global variables include information about the data uploaded to the server via the Post method
$_files is a two-dimensional array that contains 5 elements:
$_files[' upload-name ' [' Name ']. File name for uploading files from client to server
$_files[' upload-name ' [' type ']. The MIME type of the uploaded file. Whether this variable is assigned depends on the function of the browser
$_files[' upload-name ' [' Size ']. Size (in bytes) of the uploaded file
$_files[' upload-name ' [' tmp_name ']. The temporary name given before the file is moved to the final location after uploading
$_files[' upload-name ' [' Error ']. Upload status code. 5 Possible values:
Upload_err_ok. File Upload Successful
Upload_err_ini_size. The file size exceeds the maximum value set by the upload_max_filesize directive
Upload_err_form_size. The file size exceeds the maximum value specified by the Max_file_size hidden form field parameter (optional)
Upload_err_partial. Only part of the file was uploaded
Upload_no_files. No file specified in file form
More about the operating system environment:
$_ENV Super Global variable provides information about the server environment where the PHP parser resides
$_env[' HOSTNAME '. Server Host Name
$_env[' SHELL ']. System shell
Gets the information stored in the session: The $_session Super global variable contains information about all session variables
Variable: The original variable name is preceded by a dollar symbol, and another value is assigned to it
3.7 Constants
Constants refer to values that cannot be modified in a program
The Define () function defines a constant by assigning a value to a variable name in the following form:
Boolean define (string name,mixed value [, Bol case_insensitive])
If you use the optional parameter case_insensitive, and the value of this parameter is TRUE, subsequent references to this constant are not case-sensitive
You do not need to use a dollar symbol before a constant
Once defined, the defined constants cannot be redefined or canceled.
3.8 Expressions
Operand (operand): operand is an input to an expression
Operator (operator): an operator is a symbol that specifies an action in an expression
List of operators
Operator Precedence
Operator associativity
Arithmetic operators: "+", "-", "*", "/", "%"
Assignment operators: "=", "+ =", "*=", "/=", ". ="
String operator: "=", ". ="
Self-increment and decrement operators: "+ +", "--"
Based on self-increment and decrement operator placement pre-increment operation, pre-decrement operation, post-increment operation, post-decrement operation
Logical operators: "&&", "and", "| |", "or", "!", "not", "XOR"
Equality operators: "= =", "! =", "= = ="
Comparison operators: "<", ">", "<=", ">=", "($a = = 12)?" 5:-1 "(if $ A equals 12, return value 5; otherwise return value-1)
Bitwise operators: "&", "|", "^" (XOR). $a or $b contains each of the different or), "~ $b" (Non-. $b in the opposite direction), $a << $b (move left. Move a $ A bit to the left $b step), ">>" (move right)
3.9 String Insertion
Double quotes
Escape sequence: Description
\ n line break
\ r Enter
\ t Horizontal tab
\ \ counter Slash
\$ dollar Symbol
Single quotation marks
Curly Braces
Heredoc Syntax:
PHP echo <<<EXCERPT The homepage of the blog Park (that is, the homepage) can only publish original, high-quality content that allows the reader to learn something from it.
EXCERPT;?>// start and end identifiers must be the same. Here the start and end identifiers are excerpt, or the custom//start and end identifiers can only consist of alphanumeric characters and underscores, and cannot begin with a number or underscore//Start identifier must be preceded by 3 angle brackets:<<
Heredoc Instances
Nowdoc syntax
3.10 Control Structure
Conditional statements (omitted from each statement syntax)
If statement
Else statement
ElseIf statements
Switch statement
Loop statement (syntax omitted for each statement)
While statement
Do......while statements
For statement
foreach statement
Break statement and Goto statement
Continue statements
file contains statements
Include ()
Include () or include ""
Form: include (/path/to/filename)
Make sure to include only files once: include_once ()
Request file: Require ()
Require () error, the script will stop executing. Include () will continue to execute in this case
Make sure to request files only once: require_once ()
3.11 Summary
To be a successful PHP programmer, this chapter lays the foundation for extraordinary significance!
The above describes the PHP and MySQL programming chapter three essays-(2), including the aspects of the content, I hope to be interested in the PHP tutorial friends helpful.