After reading some basic knowledge of PHP, I summarized it here:
1. There are three ways to embed PHP scripts in HTML:
<scriptlanguage="php">
//嵌入方式一
echo("test");
</script>
<?
//嵌入方式二
echo"<br>test2";
?>
<?php
//嵌入方式三
echo"<br>test3";
?> |
//Embedding method one
echo("test");
</script>
<?
//Embedding method two
<?
//这里是单行注释
/*
这里是多行注释!可以写很多行注释内容
*/
?> |
echo"<br>test2";
?>
<?php
//Embedding method three
echo"<br>test3";
?> |
There is another embedding method, which is to use the same tag as Asp, but it requires modifying the relevant configuration of PHP.ini, which is not recommended.
2. PHP comments are divided into single-line and multi-line comments, which are the same as java comments.
<?
//This is a single line comment
|
<?
$a=1;
functiontest(){
echo$a;
}
test();//这里将不能输出结果“1”。
functiontest2(){
global$a;
echo$a;
}
test2();//这样可以输出结果“1”。
?> |
/*
This is a multi-line comment! You can write many lines of comments
*/
?>
Be careful not to have nested comments, such as /*aaaa/*asdfa*/asdfasdfas*/. Such comments will cause problems.
3. There are 5 main data types in PHP, integer, double, string, array, object.
4. When calling external variables within a function, you need to declare them with global first, otherwise they will not be accessible. This is a difference between PHP and other programming languages. Case code:
<?
$a=1;
functiontest(){
echo$a;
}
test();//The result "1" will not be output here.
functiontest2(){
global$a;
echo$a;
}
test2();//This can output the result "1".
?> |
Note: PHP can declare static variables inside functions. The usage is the same as in C language.
5. Variables of variables, functions of variables
<?
<?
//变量的变量
?>

<?
//变量的函数

functionfunc_1(){
}

functionfun($callback){
$callback();
}

?> |
//Variables of variables
|
<?
$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"
?> |
?>
<?
//Variable function
functionfunc_1(){
}
functionfun($callback){
$callback();
}
?>
6. PHP supports both scalar arrays and associative arrays. You can use list() and array() to create arrays. The array subscript starts from 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. Associated parameter transfer (use of &), two methods. Example:
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn