php php foundation Series Quick Start

· Interpolation operations 
will be simply referred to by a variable write a string of double quotes, called interpolation operations. For example:
$ Test = 'XX';
echo "Hello: $ test";
Note: only interpolation operations characteristic double-quoted strings.
· Variables and literals
reference to the above example. 'xx' is literal, and $ test variable.
· Data types
· Integer (integer): integer used to represent
· Float (floating-point numbers, also known as Double, double precision): used to represent all real numbers
· String (string): used to represent string
· Boolean (boolean value ): it is used to indicate true or to false
· the array (array): used to store a plurality of data items having the same type
· Obejct (object): class instance to save
a particular type
· NULL (blank): not assigned, has or it is assigned the variable is reset type is NULL NULL special value is variable.
· Resource (resources): the specific built-in functions (such as database functions) returns the resource type variable. They represent external resources (e.g., database connections).
A resource can not directly operate substantially variable, but typically they will be function returns, and must be passed as a parameter to other functions.
· Callable: usually it can be passed to the function other functions.
· Type of strength
PHP is a weakly typed language, or dynamically typed languages, the variable type is determined by the values assigned to variables.
· Type conversion
using conversion type, a variable can be converted into another type or value. Insert parentheses need to convert the temporary data type can only be before the variable type conversion in hope.
0 = $ num;
$ theNum = (a float) $ num;
second line means: the value stored in $ num taken in, which was interpreted as a float, and saves it in the $ theNum. $ theNum variable will become a floating-point type.
• Variable variables
PHP provides one of the other types of variables: Variable variables. Variable variable allows us to dynamically change the name of a variable.
This feature works with the value of a variable as the name of another variable. For example:
$ varname = 'tireqty'; // may then be substituted by $$ varname $ tireqty.
$$ varname = 5; // this code is equivalent to: $ = tireqty. 5;
· declare variables and constants
defined method:
DEFINE ( 'NAME', 'Cheng Lin');
echo NAME;
generally constant names are from uppercase letters, which is borrowed from the practice of the C language, so it is easy to distinguish between variables and constants.
Note: Constant only save Boolean, integer, string or floating-point data, these types are scalar data.
· Variable Scope
* Built-in super-global variables can be used anywhere and can be seen in the script.
· Constants, once declared, will be visible in the global; that is, they can be used both inside and outside the function.
· Global variables declared in a script are visible throughout the script, but not inside the function.
· When the internal variable function uses declared as a global variable, its name should be consistent with the global variable name.
• Create and declared inside a function it can not be seen outside the function static variable, but this value can be maintained in a number of the calling process function.
· Variables inside a function created when a function is local, and when the function terminates, the variable will not exist.
· Superglobals
that all scopes always available built-in variables
· $ GOLBALS: all global variables arrays ($ GLOBALS [ '_ SERVER']
· $ _SERVER: server environment variable array
· $ _GET: passed to the script via the GET method the array of variables
· $ _POST: variable passed to the script by POST array method
· $ _COOKIE: cookie variable array
· $ _FILES: file upload variables related to the array
· $ _ENV: environment variable array
· $ _REQUEST: all user input variable array, comprising _GET, $ _ POST $ _COOKIE input and included in the content (but not including _FILES $
· $ _SESSION: session variable array
· operators
· arithmetic operators
+ - * /%
You should be noted that, for the integer arithmetic operator is generally or double precision data. If you apply them to a string, PHP will attempt to convert the string into a number.
If it contains 'e' or "E" character, it is treated as scientific notation and converted to floating point, otherwise it will be converted into integers. PHP will look at the beginning of the string number
, and use these values as the string of numbers, if the number is not found at the beginning, the string value of 0
· string operator
.
The assignment operator
=
assignment operation · return value
as with other operators, also using the assignment operator returns a value:
echo. 1 + ($ a = 2); //. 3
* compound assignment operator
+ = - = = * /% = = =
pre- and post increment decrement counter increment decrement operators
omitted ...
· reference operator
· typically, when the value of one variable to another variable, and generates a first copy of the original variable, then it is stored in memory elsewhere.
. 5 = $ a;
$ b = $ a;
two lines first generates a copy of $ a, and then save it to the $ b. If you then change the value of $ a, $ b value will not be changed.

· To avoid the copy, you can use the reference operator:
$ A = 5;
$ b = & $ A;
reference operator is very interesting, remember that quote as an alias rather than a pointer. $ a and $ b point to the same memory address. You can make by resetting the
variable does not point to the original memory address:
unset ($ a);
resetting the variable does not change the value of $ b (7), but can destroy links and values 7 $ a in memory address.
· Comparison operators
comparison operator for comparing the two values. Comparison operator returns a logical expression based on the comparison result: true or to false;
· equality operator
equality operator == (equals two) allow the test two values are equal
· other comparison operators
===: identity, only operands are equal on both sides and have the same data type, it returns to true
<>: ranging acts as! =
logical operators
, &&, ||!
* bitwise operators
is not used, omitting
· other operators
· ternary operator
condition value if true: value if false ;?
· Error suppression operator
error suppression operator @ may be used prior to any expression, i.e., expression or may be a value calculated prior to have any value.
@ A = $ (1/0);
var_dump (A $); // to false
if there is no @ operator, this line of code will generate a warning other than 0, the use of this operator, this warning will be suppressed.
Arrays Operators
PHP provides a number of operators array, the array operator ([]) to support access array elements. In the context of some of the arrays, may also be used => operator
other array operators
operator name Use Results
+ + $ a $ b joint returns contains a $ a $ b and all the elements in the array
== $ a equivalent If == $ b $ a, $ b have the same value pairs, it returns true
=== identity if $ a === $ b $ a, $ b have the same key and the same sequence on, returns true
! = nonequivalent
<> nonequivalent
! == non-identity
Note: You can not scalar types and arrays are compared.
· Type of operator
is only one type operator: instanceof. The objects in object-oriented programming.
instanceof operator is allowed to check whether an object instance of a particular class.
sampClass {} class;
$ new new sampClass the myObject = ();
var_dump ($ sampClass the instanceof the myObject); // to true
-variable processing functions using
· most variable functions related to the type of a function test. PHP variables are the two most common functions, are gettype () and setType ()
String GetType (Mixed var);
BOOL setType (Mixed var, String of the type);
· To use gettype () function, you must give it a pass variable. It will determine the type of the variable and returns a string containing the type name: boolean, Integer,
Double (floating-point type, for historical reasons confusing), string, array, object, resource , or NULL. If one type is not a standard type of variable,
the function returns "unknown type";
· To use settype () function, you must give it a pass to change the type of a variable, and contains a list of the type described above in a type of string.
the Test = 1 $;
var_dump (GetType ($ the Test)); // Integer
var_dump (setType ($ the Test, 'Double')); // to true
var_dump (GetType ($ the Test)); // Double
· PHP also provides Some specific types of test functions. Each function uses a variable as its argument, and returns a true or to false:
is_array ()
is_double (), of is_float (), is_real () (all are both the same function)
is_long (), of is_int (), is_integer () (all are when the same function)
is_string ()
is_bool ()
is_object ()
is_resource (): whether a variable is a resource
is_null ()
is_scalar (): whether a variable is a scalar, that is, whether an integer, boolean, string or floating-point
is_numeric (): whether a variable is any type of digital or numeric string
is_callable (): whether the detected variable is valid function name
· Variable status detection function:
· isset ()
BOOL isset (Mixed var [, Mixed var [, ...]])
This function takes a variable name as an argument. Can also pass a comma-separated list of variable
· unset ()
void unset (Mixed var [, Mixed var [, ...]])
You can use the isset () function corresponding to the unset () function corresponding to unset () function to destroy a variable
· empty ()
BOOL empty (Mixed var)
· variable heavy explain
that you can achieve the purpose of converting the variable data types by calling a function. Following three functions can be used to achieve this function
int intval (mixed var [, int base = 10]): When allowed to be converted into a string variable, the specified binary radix conversion (this may be 16 hex convert a string to an integer)
float floatval (mixed var)
string strval (mixed var)
· mixed data types of
books and documents are referred to the php.net 'hybrid' type of data, in fact, PHP does not have this type. However, PHP is very flexible in the type of treatment, many functions can be more (or any)
Data type as a parameter. These types of parameters are generally allowed false "mixed" type.
· Make decisions based on conditions
control structure is a programming language used to control structure of a program or script execution process. We can classify them as a condition (or branch) structure and a repeating structural (or cyclic structure)
· switch: switch statement and js switch statement similar, except that php switch statement switch used in the comparison value is equal to the operator, so type conversion will occur.
· Break and continue: js and similar

Guess you like

Origin www.cnblogs.com/cl94/p/11261784.html