Look at the basic knowledge of PHP, and summarize it here:
1. There are three ways to embed the PHP script in HTML:
<scriptlanguage=”php”> // Embedding method one echo(“test”); </script> <? <?php |
also has an embedded method. Even if the same label <%%> is the same as ASP, it is not recommended to use PHP.ini related configuration.
2, PHP annotation division single line and multi -line annotation, and multiple lines, andjavaThe annotation method is the same.
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Be careful not to have nested notes, such as/*aaaa/*asdfa*/asdfasdfas*/, such annotations will have problems.
3. There are 5 main data types of PHP,integer,double,string,array,object。
4. Call the function external variables in the function. You need to declare it with Global first, otherwise it will not be accessed. This is PHP and otherProgramA difference. Case code:
<? $a=1; functiontest(){ echo$a; } test (); // The result will not be output “1” here. functiontest2(){ |
Note: PHP can declare static variables inside the function. Uses in C language.
5, variables of variables, variables of variables
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
6. PHP supports the array and associated array at the same time. You can use list () and array () to create arrays. like:
<? $a[0]=”abc”; $a[1]=”def”; $b[“foo”]=13; $a[]=”hello”;//$a[2]=”hello” $name[]=”jill”;//$name[0]=”jill” |
7, associated parameter transmission (& use), two methods. example:
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
8. Functional recognition. The function supports the default value in the PHP, which is the same as the C ++ style.
<? functionmakecoffee($type=”coffee”){ echo”makingacupof$type.\n”; } echomakecoffee();//”makingacupofcoffee” echomakecoffee(“espresso”);//”makingacupofespresso” /* Note: When the default value of the parameters is used, all parameters with the default value should be defined behind the parameters without silence. Otherwise, the program will not follow what you want. */ functiontest ($ type = “test”, $ ff) {// error example |
9. Several special symbols of PHP.
$ variable
& Variable Address (Add in front of the variable)
@3 3 3 3 3 (plus in front of the variable)
-> Class method or attribute
=> The elemental value of the array
?: Ternary operator
10, include () statement and Require () statement
If you need to include files according to conditions or circulation, you need to use include ().
Require () statement is just included by simply, any conditional statement or cycle is invalid.
Since include () is a special statement structure, if the statement is in a statement block, he must include him in a statement block.
<? // The following is a wrong sentence if($condition) include($file); else include($other); // The correct statement below |
Reprinted: https://www.cnblogs.com/yaojing/archive/2009/10/17/1584874.html