[php]php Summary (1)

Source: Internet
Author: User

1, the variable can be transferred continuously assigned value
2. Var_dump () Print variable information
3, Isset () and unset ()
4. Variable variable
$p = "temp";
$ $p Represents the $temp variable, that is, the value of the right-most variable is the value of the next variable
5. Variable Support Reference
Similar to C language can use & get variable address
6, the false value of the variable
0,null, 0.0, "", "0", Array (),
7. The difference between single and double quotation marks
The variable can be parsed directly in double quotes, and single quotation marks cannot be
can also parse curly braces, single quotes can not
Ability to parse escape characters (single quotes can only escape \ and '),

$a = 100;
"The score is $a" output: The score is 100
"The score is {$a}" output: The score is 100
8. Using delimiters to declare strings
$str = <<<eof
Heheheheeheheh
EOF;
Equivalent
$str = "Heheheheeheheh";
EOF is Custom
Note: The start tag must be a direct carriage return (no spaces are available)
The semicolon also returns directly after the end tag
9. Type Conversion
SetType (variable, type string);
Variable before plus ();
Intval (); Floatval (); Strval ();
10. Constants
Define (variable name string, value);
Constant () Gets the constant value
Get_defined_constants (); Get list of all constants
11. PHP supports goto statement (same as C)
12. Function Default Parameters
function Demo ($demo = "Demo") {

}
13. Variable parameter function
Function Demo () {
$arr = Func_get_args ();
$num = Func_num_args ();
}
14. Variable function
function Add () {

}
$var = "Add";
$var ();
15. Callback function
callback function: The parameter it receives is a function, then this function can be a callback function
(1) The use of variable functions is implemented
function to print digits not 0
function Remove ($var, $func) {
for ($i =0; $i < $var; $i + +) {
if ($func ($i))
Continue
echo $i;
}
}
This function is used as a parameter
function func ($var) {
if ($var%10==0)
return true;
Else
return false;
}
(2) When a parametric function is a static method of a class or a method of an object, the variable function cannot support
function Remove ($var, $func) {
for ($i =0; $i < $var; $i + +) {
if (Call_user_func_array ($func, Array ($i)))
Continue
echo $i;
}
}
Class filter{
function func ($var) {
if ($var%10==0)
return true;
Else
return false;
}
}
Remove (Array (new Filter (), "Func"));
Note: Calling the Remove function here is an array to describe the parameter function, i.e. $func=array (new Filter (), "Func")
Call_user_func_array ($func, Array ($i)) is the formal parameter of the function that assigns the elements in the following array to the front
16. The difference between require and include
(1) Require is executed at preprocessing time and wants to copy the function or content used in the require file to the calling place
(2) Fatal error occurs when require execution fails, and include is warning
17. Closure function
(1) There is a function inside the function, the parent function can return the child function, but the child function cannot have return
(2) A child function can invoke a variable inside the parent function, using the keyword use
(3) The internal variables of the parent function will remain active and will not be released
function Test () {
$a = 100;
$p = function () use (& $a) {
echo $a + +;
};
return $p;
}
$test = Test ();
$test ();
$test ();
$test ();
The value of multiple calls to $ A is in the ever increasing

[php]php Summary (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.