1, there are three ways to embed PHP scripts in HTML:
< script language = "PHP" >
Embedding mode One
Echo ("Test");
</script >
?
Embedding Mode Two
echo "<br>test2";
?>
? Php
Embedding mode Three
echo "<br>test3";
?>
There is also an embedding method that uses the same markup <%%> as the ASP, but it is not recommended to modify the php.ini related configuration.
2,php notes are Single-line and multiline comments, in the same way as Java annotations.
?
This is a single-line comment.
echo "Test";
/*
Here is a multiline comment. Can write a lot of line comment content
*/
?>
Note that there are no nested annotations, such as/*aaaa/*asdfa*/asdfasdfas*/, that can cause problems. There are 5 main data types for the
3,php, Integer,double,string,array,object.
4, calling function external variables within a function, which needs to be declared with global or inaccessible, is a difference between PHP and other programming languages. Case code: NOTE: PHP can declare a static variable inside a function. Uses in the same language as C.
5, variable variables, function of the variable
.?
$a = 1;
Function test () {
echo $a;
}
Test (); //() This will not output the result "1".
Function test2 () {
global $a;
echo $a;
}
Test2 (); //This will output the result "1".
?>
?
Variable for variables
$a = "Hello";
$ $a = "world";
echo "$a $hello"; Will output "Hello World"
echo "$a ${$a}"; will also output "Hello World"
?>
?
function of a variable
function Func_1 () {
Print ("test");
}
function Fun ($callback) {
$callback ();
}
Fun ("func_1"); This will output "test"
?>
6,php supports both scalar and associative arrays, you can use the list () and array () to create an array with the array subscript starting at 0. Such as:
?
$a [0] = "abc";
$a [1] = "DEF";
$b ["foo"] = 13;
$a [] = "Hello"; $a [2]= "Hello"
$a [] = "World"; $a [3]= "World"
$name [] = "Jill"; $name [0]= "Jill"
$name [] = "Jack"; $name [1]= "Jack"
?>
7, correlation parameter passing (use of &), two methods. Example:
.
//Method One:
function foo (& $bar) {
$bar. = " and something extra";
$str = "this is a string,";
Foo ($STR);
Echo $STR; //output:this is a string, and something extra
Echo "<br>";
Method Two:
function foo1 ($bar) {
$bar. = " and something extra";
}
$str = "this is a string,";
Foo1 ($STR);
Echo $str; //output:this is a string,
echo "<br>";
Foo1 (& $str);
Echo $str; //output:this is a string,& Nbsp;and something extra
?>
8, the default value of the function. In PHP, the function supports setting the default value, which is the same as C + + style.
;?
Function makecoffee ($type = "Coffee") {
echo making a cup of $t ype./n ";
}
Echo makecoffee (); //"Making a cup of coffee"
Echo makecoffee ("espresso"); //"Making a cup of espresso"
/*
Note: All parameters with default values when using parameter defaults should be defined behind parameters that do not have a default value. Otherwise, the program will not work as expected.
*/