After reading some basic PHP knowledge, I will summarize it here: 1. there are three measures for Embedding PHP scripts in HTML: <scriptlanguage = "php"> // method 1 echo ("test \"); </script> <? // Embedded method 2 echo "<br> test2";?> <? Php // embedded
After reading some basic PHP knowledge, I will summarize it here:
1. there are three measures for Embedding PHP scripts in HTML:
<Scriptlanguage = 'php'>
// Embedded method 1
Echo ('test \');
</Script>
<?
// Method 2
Echo '<br> test2 ';
?>
<? Php
// Embedded method 3
Echo '<br> test3 ';
?>
There is also an embedded method, that is, the application and Asp mark similar <%>, but to modify the PHP. ini coherent configuration, it is not recommended to apply.
2. PHP comments are divided into single-line and multi-line comments, which are the same as java comments.
<?
// Here is a single line comment
Echo 'test ';
/*
Here is a multi-line comment! Many lines of comments can be written.
*/
?>
Be careful not to include nested comments, such as/* aaaa/* asdfa */asdfasdfas */. such comments will display titles.
3. PHP has five important data types: integer, double, string, array, and object.
4. to call external variables in a function, you must declare them using global. Otherwise, you cannot visit them. this is a difference between PHP and other programming languages. Example code:
<?
$ A = 1;
Functiontest (){
Echo $;
}
Test (); // the result "1" cannot be output here ".
Functiontest2 (){
Global $;
Echo $;
}
Test2 (); // You can output the result "1 ".
?>
Note: PHP can declare static variables within the function. It is used in the same C language.
5. variables and functions of variables
<?
// Variable
$ A = 'hello ';
$ A = 'world ';
Echo '$ a $ hello'; // output 'helloworld'
Echo '$ a $ {$ a}'; // the same output is 'helloworld'
?>
<?
// Variable functions
Functionfunc_1 (){
Print ('test ');
}
Functionfun ($ callback ){
$ Callback ();
}
Fun ('func _ 1'); // This will output 'test'
?>
6. PHP supports both scalar arrays and associated arrays. you can use list () and array () to create arrays. the array subscript starts from 0. For example:
<?
$ 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. join parameter transfer (& application), two methods. Example:
<?
// Method 1:
Functionfoo (& $ bar ){
$ Bar. = 'andsomethingexist ';
}
$ Str = 'thisastring ,';
Foo ($ str );
Echo $ str; // output: ThisisaString, andsomethingextra
Echo '<br> ';
// Method 2:
Functionfoo1 ($ bar ){
$ Bar. = 'andsomethingexist ';
}
$ Str = 'thisastring ,';
Foo1 ($ str );
Echo $ str; // output: ThisisaString,
Echo '<br> ';
Foo1 (& $ str );
Echo $ str; // output: ThisisaString, andsomethingextra
?>
8. default function value. The default value of function support in PHP is the same as that of C.
<?
Functionmakecoffee ($ type = 'coffee '){
Echo '*** acupof $ type. \ n ';
}
Echomakecoffee (); // '*** acupofcoffee'
Echomakecoffee ('Espresso '); //' *** acupofespresso'