PHP is a dynamic interactive site to create a powerful server-side scripting language
PHP (Hypertext Preprocess Hypertext Preprocessor) is a versatile open source scripting language
<? Php PHP code?>
php file default extension ".php"
Each PHP code must end with a semicolon
The two basic output php: echo and print
Distinction echo, print and print_r of: echo may output one or more strings
Output value of only simple types of variable print, such as int, string
print_r may output a value of a variable of a complex type, if the array, the object
Output speed is faster than the print echo
php echo statement is no return value, and Print function print_r PHP is, the return value, to return Print 1 (int type), print_r returns true (bool type)
Notes php: // single-line comments
# Single-line comments
/*
Multi-line comments
*/
php variables: variables start with a $ sign, followed by the name of variables; variables must begin with a letter or an underscore character; variables can only contain letters, numbers, and the underscore character; variable names can not contain spaces, variable names are case sensitive
Note: php php statement and cool are case-sensitive; php variable underlined at the beginning is often the system comes with variables
Syntax:? <Php
$x=5;
$ Y = 6;
$z=$x+$y;
echo $z;
?>
php is a weakly typed language
php variable scope: local local variables: the function declaration, accessible only inside the function
global global variables: function external declaration may be in addition to any other part of the script to access outside the function, and access to a global variable in a function, use the global keyword
<?php $x=5; $y=10; function myTest() { global $x,$y; $y=$x+$y; } myTest(); echo $y; // 输出 15 ?> |
PHP will all global variables stored in an array called $ GLOBALS [index] in, index variable name is saved, the above code is also used to indicate the following:
<?php $x=5; $y=10; function myTest() { $GLOBALS['y']=$GLOBALS['x']+$GLOBALS['y']; } myTest(); echo $y; ?> |
When a static function is completed, all of the variables will be deleted, but static local variable declarations are not removed, then when the function is called, the variable will retain the value of a function is invoked before, but this variable still is a local variable
Parameter parameter: the value of the local variables passed to the function by calling code, the parameter is declared in the parameter list, as a function declaration part
php5 Data Type: string (string), Integer (integer), Float (float), Boolean (Boolean), Array (arrays), Object (Object), NULL (null)
String: The text in single or double quotes
Integer: no decimal places, there are three formats: decimal, hexadecimal (prefixed with 0x), octal (prefixed with 0)
NOTE: php var_dump () function returns the value of a variable data type and
Float: with fractional components, or exponential form
Boolean: TRUE or FALSE
Array: storing a plurality of variable values
<?php $cars=array("Volvo","BMW","Toyota"); var_dump($cars); ?> |
Objects
<?php class Car { var $color; function Car($color="green") { $this->color = $color; } function what_color() { return $this->color; } } function print_vars($obj) { foreach (get_object_vars($obj) as $prop => $val) { echo " $prop = $val "; } } // instantiate one object $herbie = new Car("white"); // show herbie properties echo "herbie: Properties "; print_vars($herbie); ?> |
NULL value: represents the variable has no value, the value NULL may be cleared by setting the variable to variable data
PHP5 constant
A constant is an identifier of a simple value, that value can not be changed in the script